【備忘録】Docker @ CentOS7 @ さくらのVPS

```bash
yum install docker
systemctl start docker
docker pull sameersbn/redmine
docker run -d -p 54080:80 sameersbn/redmine

#動作確認
wget http://localhost:54080
# --2016-03-19 19:19:20--  http://localhost:5480/
# Resolving localhost (localhost)... ::1, 127.0.0.1
# Connecting to localhost (localhost)|::1|:5480... failed: Connection refused.
# Connecting to localhost (localhost)|127.0.0.1|:5480... failed: Connection refused.
# そりゃそうだ。ポートがあいてない。

firewall-cmd --list-all
# public (default, active)
# interfaces: eth0
# sources:
# services: dhcpv6-client ssh
# ports:
# masquerade: no
# forward-ports:
# icmp-blocks:
# rich rules:

firewall-cmd --add-port=54080/tcp --zone=public --permanent
# success
firewall-cmd --reload
firewall-cmd --list-all
# public (default, active)
#   interfaces: eth0
#   sources:
#   services: dhcpv6-client ssh
#   ports: 54080/tcp
#   masquerade: no
#   forward-ports:
#   icmp-blocks:
#   rich rules:
# 空いた空いた

wget http://localhost:54080
# --2016-03-19 19:30:59--  http://localhost:54080/
# Resolving localhost (localhost)... ::1, 127.0.0.1
# Connecting to localhost (localhost)|::1|:54080... failed: Connection refused.
# Connecting to localhost (localhost)|127.0.0.1|:54080... failed: Connection refused.
# (´・ω・｀)

docker ps
# CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
# (´・ω・｀)????

docker ps -a
# CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
# 153811d99f0f        sameersbn/redmine   "/sbin/entrypoint.sh "   4 minutes ago       Exited (1) 4 minutes ago                        redmine
# db342270651a        sameersbn/redmine   "/sbin/entrypoint.sh "   5 minutes ago       Exited (1) 5 minutes ago                        cranky_brahmagupta
# b0997e479d98        sameersbn/redmine   "/sbin/entrypoint.sh "   21 minutes ago      Exited (1) 21 minutes ago                       fervent_khorana
# よくわからなくて3回ぐらいたたいた。なるほど?

docker run --name redmine -p 54080:80 sameersbn/redmine
# Initializing logdir...
# Initializing datadir...
# Generating OpenSSH client keys...
# Symlinking dotfiles...
# Installing configuration templates...
# Configuring redmine...
# Configuring redmine::database
# ERROR:
#   Please configure the database connection.
#   Refer http://git.io/JkE-cw for more information.
#   Cannot continue without a database. Aborting...
#  せめてエラーぐらいはだしてくれないっすかね(´・ω・｀)

# http://tkhrssk.hatenablog.com/entry/2015/02/19/041916 を参考に
mkdir -p /opt/mysql/data
docker pull sameersbn/mysql:latest
chcon -Rt svirt_sandbox_file_t /opt/mysql/data
docker run -d \
  --name=mysql \
  -e 'DB_NAME=redmine_production' \
  -e 'DB_USER=redmine' \
  -e 'DB_PASS=password' \
  -v /opt/mysql/data:/var/lib/mysql sameersbn/mysql
mkdir -p /opt/redmine/data
# ↓はコントロールが帰ってこないのでscreenか何かで起動するべき
chcon -Rt svirt_sandbox_file_t /opt/redmine/data
docker run -p 54080:80 --name=redmine -it --rm --link mysql:mysql \
  -v /opt/redmine/data:/home/redmine/data \
  sameersbn/redmine
docker ps
# CONTAINER ID        IMAGE               COMMAND                  CREATED             # STATUS              PORTS                            NAMES
# 167804a249c5        sameersbn/redmine   "/sbin/entrypoint.sh "   33 seconds ago      Up 32 seconds       443/tcp, 0.0.0.0:54080->80/tcp   redmine
# cce0649ee0f7        sameersbn/mysql     "/sbin/entrypoint.sh "   15 minutes ago      Up 15 minutes       3306/tcp                         mysql

wget http://localhost:54080
# --2016-03-19 20:21:27--  http://localhost:54080/
# Resolving localhost (localhost)... ::1, 127.0.0.1
# Connecting to localhost (localhost)|::1|:54080... connected.
# HTTP request sent, awaiting response... 200 OK
# Length: 3745 (3.7K) [text/html]
# Saving to: ‘index.html’
# 
# 100%[===============================>] 3,745       --.-K/s   in 0s
# 
# 2016-03-19 20:21:28 (218 MB/s) - ‘index.html’ saved [3745/3745]
# ヽ(=´▽`=)ﾉ
```

まんぞく