启动多个centos-ssh-http镜像容器
centos-ssh-http镜像是之前文章中构建的;
查看镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
sw-centos-ssh-http v1.0.0 b9fa9fc7eb88 8 minutes ago 479.2 MB
sw-centos-ssh v1.0.1 a18e5ad19f04 24 minutes ago 315.2 MB
docker.io/centos latest 3bee3060bfc8 3 weeks ago 192.5 MB
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
12c487801c50 sw-centos-ssh:v1.0.1 "/usr/sbin/init" 23 minutes ago Up 23 minutes 0.0.0.0:8031->22/tcp swtest1
3aee75b07ec2 docker.io/centos "/bin/bash" 39 minutes ago Exited (0) 36 minutes ago pensive_jones
启动容器-主机端口80
[root@localhost ~]# docker run -d -p 80:80 --name=myhttpd sw-centos-ssh-http:v1.0.0 /usr/sbin/init
8b333b976f488f260fa74fae5e7c395b6cea5a75beb0205d4c4e686b5da34f70
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8b333b976f48 sw-centos-ssh-http:v1.0.0 "/usr/sbin/init" 6 seconds ago Up 5 seconds 22/tcp, 0.0.0.0:80->80/tcp myhttpd
12c487801c50 sw-centos-ssh:v1.0.1 "/usr/sbin/init" 27 minutes ago Up 27 minutes 0.0.0.0:8031->22/tcp swtest1
3aee75b07ec2 docker.io/centos "/bin/bash" 44 minutes ago Exited (0) 40 minutes ago pensive_jones
启动容器-主机端口81
[root@localhost ~]# docker run -d -p 81:80 --name=myhttpd81 sw-centos-ssh-http:v1.0.0 /usr/sbin/init
920efa86ecea18052b074f9d92efdd31c3a5cf31626dda2a877c880ac4dedc70
[root@localhost ~]#
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
920efa86ecea sw-centos-ssh-http:v1.0.0 "/usr/sbin/init" 18 seconds ago Up 17 seconds 22/tcp, 0.0.0.0:81->80/tcp myhttpd81
8b333b976f48 sw-centos-ssh-http:v1.0.0 "/usr/sbin/init" About a minute ago Up About a minute 22/tcp, 0.0.0.0:80->80/tcp myhttpd
12c487801c50 sw-centos-ssh:v1.0.1 "/usr/sbin/init" 28 minutes ago Up 28 minutes 0.0.0.0:8031->22/tcp swtest1
3aee75b07ec2 docker.io/centos "/bin/bash" 45 minutes ago Exited (0) 41 minutes ago pensive_jones
[root@localhost ~]#
测试
[root@localhost ~]# curl -I 192.168.2.10
[root@localhost ~]# curl -I 192.168.2.10:81
远程访问容器
[root@localhost ~]# docker inspect 920efa86ecea | grep "IPA"
"SecondaryIPAddresses": null,
"IPAddress": "172.17.0.4",
"IPAMConfig": null,
"IPAddress": "172.17.0.4",
[root@localhost ~]# ssh -l root 172.17.0.4
The authenticity of host '172.17.0.4 (172.17.0.4)' can't be established.
ECDSA key fingerprint is 54:41:3b:63:06:3c:f4:99:6b:32:10:04:5f:40:6b:51.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.17.0.4' (ECDSA) to the list of known hosts.
root@172.17.0.4's password:
Last login: Thu Jun 29 07:54:28 2017 from 172.17.0.1
[root@920efa86ecea ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.4 netmask 255.255.0.0 broadcast 0.0.0.0
exit
[root@localhost ~]#