欢迎光临
我的个人博客

centos7 使用Dockerfile重置centos初始镜像

下载docker镜像
docker pull docker.io/centos

随便进入一个文件夹
命令
vi Dokerfile

然后复制

# VERSION 1.0
# CHORSE ONE IMAGE
FROM docker.io/centos

# THE CREATER
MAINTAINER Zhuang Qian "smallchill@163.com"

# RUM YUM
RUN yum install openssh-server sudo net-tools -y
RUN yum install java-1.7.0-openjdk* -y 
# RUN yum provides '*/applydeltarpm' 
# RUN yum install deltarpm -y
# RUN yum install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel lrzsz -y

# RUN SED
RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config

# ADD FILE
# ADD apache-tomcat-7.0.72.tar.gz /usr/local
# ADD nginx-1.10.1.tar.gz /usr/local/src

# INSTALL TOMCAT
# WORKDIR /usr/local
# RUN mv apache-tomcat-7.0.72 tomcat

# INSTALL NGINX
# WORKDIR /usr/local/src/nginx-1.10.1
# RUN ./configure --prefix=/usr/local/nginx && make && make install

# CLEAN
RUN yum clean all

# ADD USER
RUN echo "root:qazwsx" | chpasswd
RUN useradd admin
RUN echo "admin:admin" | chpasswd
RUN echo "admin ALL=(ALL) ALL" >> /etc/sudoers

# SSH-KEYGEN
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
RUN ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key

# START SSH
RUN mkdir /var/run/sshd
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]

注意:查看第一行是否没有复制完全

命令:
docker build -f Dockerfile -t smallchill/centos .

开启:
docker run -d -p 2222:22 -p 2280:80 smallchill/centos /usr/sbin/sshd -D

连接:
ssh root@localhost -p 2222

转载请标明来源:ibear » centos7 使用Dockerfile重置centos初始镜像

分享到:更多 ()

Where there is a will there is a way

我的新浪微博