docker封装镜像

一、docker镜像的封装(httpd服务)

vim dvd.repo

[rhel7]
name=rhel7
baseurl=http://172.25.20.250/rhel7.3
gpgcheck=0

vim Dockerfile

FROM rhel7
EXPOSE 80
COPY dvd.repo /etc/yum.repos.d/dvd.repo
RUN rpmdb --rebuilddb && yum install -y httpd && yum clean all 
CMD ["/usr/sbin/httpd","-D","FOREGROUND"]

[root@foundation20 web]# docker build -t rhel7:v1 .

二、docker镜像的封装(sshd服务)

vim Dockerfile

FROM rhel7 
EXPOSE 22 
COPY dvd.repo /etc/yum.repos.d/dvd.repo 
RUN rpmdb --rebuilddb && yum install -y openssh-server openssh-clients && yum clean all&& ssh-keygen -q -t rsa -f /etc/ssh/ssh_host_rsa_key -N "" && ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N "" && ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ed25519_key -N "" && echo root:westos | chpasswd 
CMD ["/usr/sbin/sshd","-D"]

vim dvd.repo

[rhel7]
name=rhel7
baseurl=http://172.25.20.250/rhel7.3
gpgcheck=0

docker build -t rhel7:v2 .

三、docker镜像的封装(通过supervisord,将httpd和sshd结合起来)

vim dvd.repo

[dvd]
name=rhel7.0
baseurl=http://172.25.254.250/rhel7.0/x86_64/dvd/
gpgcheck=0

[docker]
name=docker
baseurl=http://172.25.254.20/docker
gpgcheck=0

vim Dockerfile

FROM rhel7
EXPOSE 80 22
COPY dvd.repo /etc/yum.repos.d/dvd.repo
COPY supervisord.conf /etc/supervisord.conf
RUN rpmdb --rebuilddb && yum install -y httpd openssh-server supervisor && yum clean all && ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N "" -q && ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N "" -q && ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N "" -q && echo root:westos | chpasswd
CMD ["/usr/bin/supervisord"]

vim supervisord.conf

[supervisord]
nodaemon=true

[program:httpd]
command=/usr/sbin/httpd

[program:sshd]
command=/usr/sbin/sshd -D

docker build -t rhel7:v3 .

三、docker镜像的封装(nginx)

vim Dockerfile

FROM rhel7
EXPOSE 80
ADD nginx-1.14.0.tar.gz /mnt
COPY dvd.repo /etc/yum.repos.d/dvd.repo
RUN rpmdb --rebuilddb && yum install -y gcc pcre-devel openssl-devel make && cd /mnt/nginx-1.14.0 && sed -i 's/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g' auto/cc/gcc  && ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio && make && make install && cd .. && rm -fr /mnt/nginx-1.14.0 && yum remove gcc pcre-devel openssl-devel  make -y && yum clean all
FROM rhel7 
COPY --from=build /usr/local/nginx /usr/local/nginx
CMD ["/usr/local/nginx/sbin/nginx","-g","daemon off;"]

vim dvd.repo

[dvd]
name=rhel7.0
baseurl=http://172.25.254.250/rhel7.2
gpgcheck=0

docker build -t rhel7:v4 .

 

vim Dockerfile

FROM nginx as base

# https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
ARG TIME_ZONE

RUN mkdir -p /opt/var/cache/nginx && \
    cp -a --parents /usr/lib/nginx /opt && \
    cp -a --parents /usr/share/nginx /opt && \
    cp -a --parents /var/log/nginx /opt && \
    cp -aL --parents /var/run /opt && \
    cp -a --parents /etc/nginx /opt && \
    cp -a --parents /etc/passwd /opt && \
    cp -a --parents /etc/group /opt && \
    cp -a --parents /usr/sbin/nginx /opt && \
    cp -a --parents /lib/x86_64-linux-gnu/libpcre.so.* /opt && \
    cp -a --parents /lib/x86_64-linux-gnu/libz.so.* /opt && \
    cp -a --parents /lib/x86_64-linux-gnu/libc.so.* /opt && \
    cp -a --parents /lib/x86_64-linux-gnu/libdl.so.* /opt && \
    cp -a --parents /lib/x86_64-linux-gnu/libpthread.so.* /opt && \
    cp -a --parents /lib/x86_64-linux-gnu/libcrypt.so.* /opt && \
    cp -a --parents /usr/lib/x86_64-linux-gnu/libssl.so.* /opt && \
    cp -a --parents /usr/lib/x86_64-linux-gnu/libcrypto.so.* /opt && \
    cp /usr/share/zoneinfo/${TIME_ZONE:-ROC} /opt/etc/localtime

FROM gcr.io/distroless/base

COPY --from=base /opt /

EXPOSE 80

ENTRYPOINT ["nginx", "-g", "daemon off;"]

vim dvd.repo

[dvd]
name=rhel7.0
baseurl=http://172.25.254.250/rhel7.2
gpgcheck=0

docker build -t rhel7:v5 .

 

你可能感兴趣的:(docker封装镜像)