[ root@dc02 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511(Core)
[ root@dc02 ~]# uname -r
3.10.0- 327. el7.x86_64
setenforce 0
sed -i 's#SELINUX=enforcing#SELINUX=disabled#'/etc/selinux/config
systemctl disable firewalld.service
systemctl stop firewalld.service
[ root@dc02 ~]# yum install -y docker
[ root@dc02 ~]# cat >/etc/docker/daemon.json <<EOF
>{>" registry-mirrors":["https://docker.mirrors.ustc.edu.cn"]>}> EOF
[ root@dc02 ~]# cat /etc/docker/daemon.json
{" registry-mirrors":["https://docker.mirrors.ustc.edu.cn"]}
[ root@dc02 ~]# systemctl daemon-reload
[ root@dc02 ~]# systemctl enable docker
[ root@dc02 ~]# systemctl start docker
[ root@dc02 ~]# systemctl status docker
[ root@dc02 ~]# docker pull centos
Using default tag: latest
Trying to pull repository docker.io/library/centos ...
latest: Pulling from docker.io/library/centos
7 dc0dca2b151: Pull complete
Digest: sha256:b67d21dfe609ddacf404589e04631d90a342921e81c40aeaf3391f6717fa5322
Status: Downloaded newer image for docker.io/centos:latest
[ root@dc02 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/centos latest 49f7960eb7e4 7 weeks ago 200 MB
[ root@dc02 ~]# docker run -it --name mynginx centos /bin/bash
[ root@9d76d200aae9 /]# yum install -y wget vim
[ root@9d76d200aae9 /]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[ root@9d76d200aae9 /]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[ root@9d76d200aae9 /]# yum install -y nginx
# Dockerは、デフォルトでnginxをバックグラウンドで実行することを禁止しています
[ root@9d76d200aae9 /]# vim /etc/nginx/nginx.conf
# に"user nginx;"以下に行を追加します"daemon off;"
[ root@9d76d200aae9 /]# nginx -t
[ root@9d76d200aae9 /]# nginx
コマンドラインは起動後に作成されるため、新しいSSH接続を開いてイメージを表示します
[ root@dc02 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9 d76d200aae9 centos "/bin/bash"14 minutes ago Up 14 minutes mynginx
[ root@dc02 ~]# docker commit -m "add new docker images" mynginx test/nginx:v1
sha256:5e28845136a33dc8e6175248086a90f9195dda4bdfc014a89b7ee32e37cc24d0
[ root@dc02 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test/nginx v1 5e28845136a3 About a minute ago 420 MB
docker.io/centos latest 49f7960eb7e4 7 weeks ago 200 MB
nginx接続をテストします
[ root@dc02 ~]# docker run -p 80:80--name test_nginx 5e28845136a3 nginx
図に示すように、構成は成功しています
Recommended Posts