Docker使用Dockerfile创建支持ssh服务自启动的容器镜像
2014-11-29 21:46
1251 查看
1. 首先创建一个Dockerfile文件,文件内容如下
Dockerfile文件有自己的语法和命令,具体可以参考Docker的官方文档。
2. 有了Dockerfile文件以后,就可以根据Dockerfile来创建image文件了,在Dockerfile所在的目录下,运行下面的命令
命令成功后,就会创建一个名字为centos6-ssh的image,可以使用“sudo docker images”来查看。
3. 此时就可以根据上面创建出来的image文件来创建自己的容器了,下面的命令会创建一个名字为“mytest”的容器。
4. 有了容器,就可以测试我们的ssh服务了。
4.1 运行“sudo docker inspect mytest”,查看当前启动容器IP地址,然后运行下面的命令来测试
4.2 另外,也可以通过docker的端口映射来访问, 使用“sudo docker port mytest 22”查看当前容器的22端口对应的宿主机器的端口,然后通过下面的命令来访问
转自:http://www.kongxx.info/blog/?p=59
# 选择一个已有的os镜像作为基础 FROM centos:centos6 # 镜像的作者 MAINTAINER Fanbin Kong "kongxx@hotmail.com" # 安装openssh-server和sudo软件包,并且将sshd的UsePAM参数设置成no RUN yum install -y openssh-server sudo RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config # 添加测试用户admin,密码admin,并且将此用户添加到sudoers里 RUN useradd admin RUN echo "admin:admin" | chpasswd RUN echo "admin ALL=(ALL) ALL" >> /etc/sudoers # 下面这两句比较特殊,在centos6上必须要有,否则创建出来的容器sshd不能登录 RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key # 启动sshd服务并且暴露22端口 RUN mkdir /var/run/sshd EXPOSE 22 CMD ["/usr/sbin/sshd", "-D"]
Dockerfile文件有自己的语法和命令,具体可以参考Docker的官方文档。
2. 有了Dockerfile文件以后,就可以根据Dockerfile来创建image文件了,在Dockerfile所在的目录下,运行下面的命令
sudodocker build -t centos6-ssh.
命令成功后,就会创建一个名字为centos6-ssh的image,可以使用“sudo docker images”来查看。
3. 此时就可以根据上面创建出来的image文件来创建自己的容器了,下面的命令会创建一个名字为“mytest”的容器。
sudodocker run -d -P --name=mytest centos6-ssh
4. 有了容器,就可以测试我们的ssh服务了。
4.1 运行“sudo docker inspect mytest”,查看当前启动容器IP地址,然后运行下面的命令来测试
sshadmin@<容器IP>
4.2 另外,也可以通过docker的端口映射来访问, 使用“sudo docker port mytest 22”查看当前容器的22端口对应的宿主机器的端口,然后通过下面的命令来访问
sshadmin@<宿主机器IP> -p <宿主机器端口>
转自:http://www.kongxx.info/blog/?p=59
相关文章推荐
- 使用Dockerfile创建支持ssh服务自启动的容器镜像
- Docker使用Dockerfile创建支持ssh服务自启动的容器镜像
- Docker使用Dockerfile创建支持ssh服务自启动的容器镜像
- Docker使用Dockerfile创建支持ssh服务自启动的容器镜像
- Docker使用Dockerfile创建支持ssh服务自启动的容器镜像
- Docker使用Dockerfile创建支持ssh服务自启动的容器镜像
- 使用Dockerfile构建支持ssh服务自启动的容器镜像
- Docker实战:使用Dockerfile创建带Apache服务并支持ssh的Centos Docker镜像
- Dockerfile创建支持ssh服务自启动的容器
- Docker实战:使用Dockerfile创建带tomcat服务并支持ssh的Centos Docker镜像
- Docker实战:使用Dockerfile创建带nginx服务并支持ssh的Centos Docker镜像
- Docker创建支持ssh服务的容器和镜像
- Docker创建支持ssh服务的容器和镜像
- 使用dockerfile创建支持ssh远程的镜像
- 使用Dockerfile创建nginx服务容器镜像
- Docker创建支持ssh服务的容器和镜像
- Docker创建支持ssh服务的容器和镜像
- 使用dockerfile创建支持ssh远程的镜像
- 使用Dockerfile创建一个带 ssh 服务的基础镜像
- 用dockerfile创建支持ssh服务的centos镜像