Dockerのインストール
RPMをインストール
$ sudo yum install docker
$ docker -v
Docker version 1.12.6, build 1398f24/1.12.6
Dockerサービス起動
$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: http://docs.docker.com
$ sudo systemctl start docker
$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Sun 2017-06-25 14:33:35 JST; 9s ago
Docs: http://docs.docker.com
Main PID: 10202 (dockerd-current)
CGroup: /system.slice/docker.service
├─10202 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-cu...
└─10205 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-con...
DockerImage(Nginx)をPull
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
$ sudo docker search nginx
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/nginx Official build of Nginx. 6267 [OK]
...
$ sudo docker pull nginx
Using default tag: latest
Trying to pull repository docker.io/library/nginx ...
latest: Pulling from docker.io/library/nginx
Digest: sha256:72c7191585e9b79cde433c89955547685db00f3a8595a750339549f6acef7702
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/nginx latest c246cd3dd41d 2 days ago 107.4 MB
コンテナを起動
$ sudo docker run --name=nginx01 -p 8080:80 -d nginx
d1e2f3c4d8743c4454550339f3c91b31b8a38baa078ea92b49e20c60af041529
テスト
$ curl http://localhost:8080/
...
コンテナのログ確認
$ sudo docker logs d1e2f3c4d874
172.17.0.1 - - [25/Jun/2017:07:47:55 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"
コンテナに接続
$ sudo docker exec -it d1e2f3c4d8743 /bin/bash
# cat /etc/nginx/nginx.conf
...
root@d1e2f3c4d874:/usr/local/bin# exit
コンテナを停止
$ sudo docker stop nginx01
nginx01
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
コンテナを起動
$ sudo docker start nginx01
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d1e2f3c4d874 nginx "nginx -g 'daemon off" 18 minutes ago Exited (0) 4 seconds ago nginx01
コンテナを削除
$ sudo docker stop nginx01
nginx01
$ sudo docker rm nginx01
nginx01
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
イメージを削除
$ sudo docker rmi nginx
Untagged: nginx:latest
Untagged: docker.io/nginx@sha256:72c7191585e9b79cde433c89955547685db00f3a8595a750339549f6acef7702
Deleted: sha256:c246cd3dd41d35f9deda43609cdeaa9aaf04d3658f9c5e38aad25c4ea5efee10
Deleted: sha256:faff6e89a68845db6912629dd8b5647545f9198c5e312327a853508f25398c4d
Deleted: sha256:17634c028290a76bf93f15b178f7534cca4a38aede119fa760e319019a7bf9c7
Deleted: sha256:54522c622682789028c72c5ba0b081d42a962b406cbc1eb35f3175c646ebf4dc
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker run コマンドオプション
-p:コンテナとホストのポートを紐づける
-d:バックグラウンドで実行
-it:ホストとコンテナ間の標準出力をつなぐ
-name:コンテナに名前を付ける
-v:Data Volumeの指定等
<その他>
systemctlでサービスを起動する( /sbin/initを指定する)
ex) docker run --name=nginx01 -p 8080:80 -d nginx /sbin/init
この記事が気に入ったらサポートをしてみませんか?