docker
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker相关的知识,希望对你有一定的参考价值。
发布docker容器的web服务
查看本地镜像
将镜像启动为容器 new_centos
[[email protected] ~]# docker run --name new_centos -itd centos /bin/bash
进入容器 new_centos中安装vim,epel-release,net-tools,nginx,启动nginx时报错
将容器 new_centos 打包成镜像
[[email protected]ux-002 ~]# docker commit new_centos centos:nginx
容器映射,进入到容器里,再次启动nginx
[[email protected] ~]# docker run -itd --privileged -e "container=docker" -p 8080:80 centos:nginx /usr/sbin/init
1fa78208c57109cb501c18a176dd9fb2f77620e3285100628f86c21e0cfc887f
[[email protected] ~]# docker exec -it 1fa78208c5 /bin/bash
[[email protected] /]# systemctl start nginx
在浏览器中访问容器
发布docker容器的sshd服务
[[email protected] ~]# docker run -itd centos
d2b2f907f72ce7bf1143e79315ad41352db1d5924c1487baf6e6892d1384e6cd
[[email protected] ~]# docker exec -it d2b2f907f72c bash
[[email protected] /]# yum install openssh openssh-clients openssh-server -y
[[email protected] /]# exit
[[email protected] ~]# 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
[[email protected] ~]# docker commit d2b2f907f72c centos:sshd
sha256:97b04b37ef07a8f8bd8ef44f97a9d9886ef3e9f5f64be5d6ae028ec351fc219a
[[email protected] ~]# docker run -itd --privileged -p 9000:22 centos:sshd /usr/sbin/init
e7eb5afce1f9c3b294fdfa30e6d99d3c6b42e67b869077ac0f23d47f5348fbfb
[[email protected] ~]# docker exec -it e7eb5afc bash
[[email protected] /]# systemctl start sshd
[[email protected] /]# 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.
以上是关于docker的主要内容,如果未能解决你的问题,请参考以下文章