Docker
Docker のインストール方法
インストール方法
https://docs.docker.com/install/linux/docker-ce/centos/
インストール方法は、いくつかあるらしい。(リポジトリをセットアップする。rpm から入れる。テストと開発の環境を入れるなど)
CentOS 7 を minimal install した場合。
yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum install docker-ce docker-ce-cli containerd.io
起動
systemctl start docker
[root@centos7 yum.repos.d]# docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:0e11c388b664df8a27a901dce21eb89f11d8292f7fca1b3e3c4321bf7897bffe Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
OS起動時に docker を起動するようにする
systemctl enable docker
nginx を動かしてみる
Docker Official Images
https://hub.docker.com/_/nginx
フォルダ /home/htdocs01/ を作成
index.html を配置する
<html> <head><title>test</title></head> <body> test </body> </html>
[root@centos7 home]# docker run --name some-nginx -v /home/htdocs01:/usr/share/nginx/html:ro -d -p 8081:80 nginx Unable to find image 'nginx:latest' locally latest: Pulling from library/nginx 743f2d6c1f65: Pull complete 6bfc4ec4420a: Pull complete 688a776db95f: Pull complete Digest: sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68 Status: Downloaded newer image for nginx:latest 0ff7e07ffd1fe5b22c57891c72405372fd86689704bbfbf1c553b50bd33e0e3b
–name : コンテナの名前
-v : コンテンツを含むディレクトリ (volume ?)
-d : バックグランドで実行(daemon)
-p : ポートを指定
[root@centos7 htdocs01]# curl http://localhost:8081/ <html> <head><title>test</title></head> <body> test </body> </html> [root@centos7 htdocs01]#
停止し削除する
[root@centos7 htdocs01]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 254f9174cae7 nginx "nginx -g 'daemon of…" 11 minutes ago Up 11 minutes 0.0.0.0:8081->80/tcp some-nginx [root@centos7 htdocs01]# docker stop 254f9174cae7 254f9174cae7 [root@centos7 htdocs01]# docker rm 254f9174cae7 254f9174cae7 [root@centos7 htdocs01]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@centos7 htdocs01]#