Centos6-Docker-sshd

利用dockerfile创建容器并启动sshd

一、创建一个Dockerfile文件

[root@abel ~]# vim Dockerfile

# 选择一个已有的操作系统镜像作为基础
FROM centos6:latest
MAINTAINER abel "[email protected]"
# 安装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
RUN echo "root:centos" | chpasswd
#将基础镜像的/etc/ssh/目录下的ssh_host_rsa_key ,ssh_host_rsa_key.pub和ssh_host_dsa_key ,ssh_host_dsa_key.pub 删除或者不需要执行下面的俩句。
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN mkdir /var/run/sshd# 启动sshd服务
EXPOSE 22#暴露22端口
CMD ["/usr/sbin/sshd", "-D"]
二、 根据Dockerfile来创建image,在Dockerfile所在的目录运行如下命令
[root@abel ~]# docker build -t centos6-sshd
[root@abel ~]# docker images 
三、根据创建出来的image文件启动容器,命名为“abel” 
[root@abel ~]# docker run -d -P --name=abel centos6-sshd
四、查看容器IP地址

[root@abel ~]# docker inspect test

最后ssh测试登陆,ok.............

猜你喜欢

转载自blog.csdn.net/abel_dwh/article/details/78469093
今日推荐