普通的centos镜像内执行yum总是报错,所以,需要构建更丰富的centos7
下载repo
把Centos-7.repo放到你Dockerfile的同级目录(有的可能叫Centos-Base.repo)
下载centos7的镜像到本地
docker pull centos:7
编写dockerfile
制作构建Docker镜像的文件Dockerfile,目的是安装配置SSH服务,以便在容器中允许SSH连接
FROM centos:7
ADD Centos-7.repo /etc/yum.repos.d/CentOS-Base.repo
RUN yum install -y openssh-server sudo
RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
RUN yum install -y openssh-clients
RUN echo "root:111111" | chpasswd
RUN echo "root ALL=(ALL) ALL" >> /etc/sudoers
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
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
制作了新镜像centos7-ssh
docker build -f ./dockerfile -t="centos7-ssh" .