一、部署sshd镜像
[root@localhost ~]
[root@localhost ~]
[root@localhost sshd]
from centos:7 //基于基础镜像centos
MAINTAINER The Centos Project <cloud-centos> //维护镜像的用户信息
RUN yum -y update //更新yum仓库
RUN yum -y install openssh* net-tools lsof telnet passwd //安装必要的软件包
RUN echo '123456' | passwd --stdin root //为root用户设置用户密码
RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config //修改配置文件
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key //生成密钥
RUN sed -i '/^session\s\+required\s\+pam_loginuid.so/s/^/#/' /etc/pam.d/sshd
RUN mkdir -p /root/.ssh && chown root.root /root && chmod 700 /root/.ssh
EXPOSE 22 //开启22端口
CMD ["/usr/sbin/sshd","-D"] //启动容器
[root@localhost sshd]
[root@localhost sshd]
[root@localhost sshd]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4c9b29694204 sshd:new "/usr/sbin/sshd -D" 3 minutes ago Up 3 minutes 0.0.0.0:32768->22/tcp vibrant_shirley
b8242fe14868 nginx:latest "/docker-entrypoint.…" 19 hours ago Up 19 hours 80/tcp docker_nginx
[root@localhost sshd]
输入密码123456
二、部署systemctl镜像
- dockerfile基于上面sshd镜像容器创建systemctl镜像容器
[root@localhost ~]
[root@localhost ~]