docker 构建可远程连接得 centos 镜像
- FROM centos:6.8
- # 镜像的作者
- MAINTAINER yu.zhang
- # 添加测试用户 root, 密码 root, 并且将此用户添加到 sudoers 里
- RUN yum install -y openssh-server sudo openssh-clients net-tools && sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config && echo "root:123456" | chpasswd && echo "root ALL=(ALL) ALL">> /etc/sudoers
- # 下面这两句比较特殊, 在 centos6 上必须要有, 否则创建出来的容器 sshd 不能登录
- RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key && ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key && mkdir /var/run/sshd
- # 启动 sshd 服务并且暴露 22 端口
- EXPOSE 22
- CMD ["/usr/sbin/sshd", "-D"]
来源: http://www.bubuko.com/infodetail-2561151.html