方法1mkdir ss
cd ss/
touch Dockerfile //名字必须是这个
cp /etc/yum.repos.d/dvd.repo .
vim 1.sh
#!/bin/bash
EnvironmentFile=/etc/sysconfig/sshd
/usr/sbin/sshd -D &
EnvironmentFile=/etc/sysconfig/httpd
/usr/sbin/httpd -DFOREGROUND
chmod 755 1.sh
vim Dockerfile
FROM centos
RUN rm -rf /etc/yum.repos.d/*
ADD dvd.repo /etc/yum.repos.d/
ADD 1.sh /etc/init.d/1.sh
RUN yum -y install httpd openssh-server net-tools vim-enhanced iproute bash-completion psmisc initscripts
RUN echo 1 | passwd --stdin root
RUN /usr/sbin/sshd-keygen
EXPOSE 80
EXPOSE 22
CMD ["/etc/init.d/1.sh"]
方法2mkdir ss
cd ss/
touch Dockerfile //名字必须是这个
cp /etc/yum.repos.d/dvd.repo .
vim 1.sh
#!/bin/bash
/usr/sbin/sshd -D &
/usr/sbin/httpd -DFOREGROUND
vim Dockerfile
FROM centos
RUN rm -rf /etc/yum.repos.d/*
ADD dvd.repo /etc/yum.repos.d/
ADD 1.sh /etc/init.d/1.sh
RUN yum -y install httpd openssh-server net-tools vim-enhanced iproute bash-completion psmisc initscripts
RUN echo 1 | passwd --stdin root
ENV EnvironmentFile=/etc/sysconfig/httpd
EXPOSE 80
ENV EnvironmentFile=/etc/sysconfig/sshd
RUN /usr/sbin/sshd-keygen
EXPOSE 22
CMD [“/bin/bash”,"/etc/init.d/1.sh"]
[[email protected] ss]# docker build -t moo:last .
如果出现/usr/sbin/sshd-keygen: line 10: /etc/rc.d/init.d/functions: No such file or directory 报错 这个包能解决initscripts
原文地址:http://blog.51cto.com/13740508/2134332