发布docker容器的web服务
查看本地镜像
将镜像启动为容器 new_centos
[root@apenglinux-002 ~]# docker run --name new_centos -itd centos /bin/bash
进入容器 new_centos中安装vim,epel-release,net-tools,nginx,启动nginx时报错
将容器 new_centos 打包成镜像
[root@apenglinux-002 ~]# docker commit new_centos centos:nginx
容器映射,进入到容器里,再次启动nginx
[root@apenglinux-002 ~]# docker run -itd --privileged -e "container=docker" -p 8080:80 centos:nginx /usr/sbin/init
1fa78208c57109cb501c18a176dd9fb2f77620e3285100628f86c21e0cfc887f
[root@apenglinux-002 ~]# docker exec -it 1fa78208c5 /bin/bash
[root@1fa78208c571 /]# systemctl start nginx
在浏览器中访问容器
发布docker容器的sshd服务
[root@apenglinux-002 ~]# docker run -itd centos
d2b2f907f72ce7bf1143e79315ad41352db1d5924c1487baf6e6892d1384e6cd
[root@apenglinux-002 ~]# docker exec -it d2b2f907f72c bash
[root@d2b2f907f72c /]# yum install openssh openssh-clients openssh-server -y
[root@d2b2f907f72c /]# exit
[root@apenglinux-002 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d2b2f907f72c centos "/bin/bash" 3 minutes ago Up 3 minutes pedantic_johnson
1fa78208c571 centos:nginx "/usr/sbin/init" 41 minutes ago Up 41 minutes 0.0.0.0:8080->80/tcp stupefied_chandrasekhar
[root@apenglinux-002 ~]# docker commit d2b2f907f72c centos:sshd
sha256:97b04b37ef07a8f8bd8ef44f97a9d9886ef3e9f5f64be5d6ae028ec351fc219a
[root@apenglinux-002 ~]# docker run -itd --privileged -p 9000:22 centos:sshd /usr/sbin/init
e7eb5afce1f9c3b294fdfa30e6d99d3c6b42e67b869077ac0f23d47f5348fbfb
[root@apenglinux-002 ~]# docker exec -it e7eb5afc bash
[root@e7eb5afce1f9 /]# systemctl start sshd
[root@e7eb5afce1f9 /]# passwd
Changing password for user root.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.