dockerfile多阶段构建制作离线yum源

dockerfile多阶段构建制作离线yum源

参考:https://blog.csdn.net/networken/article/details/89712130

目录结构:

Dockerfile

#########################################################################################
FROM centos:7.4.1708 as build0
ENV EPEL_RELEASE=http://mirrors.aliyun.com/repo/epel-7.repo \
    DOCKER_REPO=https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
COPY yum-repo/pkg.list /
RUN mkdir /rpms \
    && yum install -y  yum-utils \
    && yum-config-manager --add-repo $EPEL_RELEASE \
    && yum-config-manager --add-repo $DOCKER_REPO \
    && yum install -y --downloadonly --downloaddir=/rpms $(cat /pkg.list)

#########################################################################################
FROM centos:7.5.1804 as build1
ENV EPEL_RELEASE=http://mirrors.aliyun.com/repo/epel-7.repo \
    DOCKER_REPO=https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
COPY yum-repo/pkg.list /
RUN mkdir /rpms \
    && yum install -y  yum-utils \
    && yum-config-manager --add-repo $EPEL_RELEASE \
    && yum-config-manager --add-repo $DOCKER_REPO \
    && yum install -y --downloadonly --downloaddir=/rpms $(cat /pkg.list)

#########################################################################################
FROM centos:7.6.1810 as build2
ENV EPEL_RELEASE=http://mirrors.aliyun.com/repo/epel-7.repo \
    DOCKER_REPO=https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
COPY yum-repo/pkg.list /
RUN mkdir /rpms \
    && yum install -y  yum-utils  createrepo \
    && yum-config-manager --add-repo $EPEL_RELEASE \
    && yum-config-manager --add-repo $DOCKER_REPO \
    && yum install -y --downloadonly --downloaddir=/rpms $(cat /pkg.list)

COPY --from=build0 /rpms/* /rpms/
COPY --from=build1 /rpms/* /rpms/
RUN createrepo /rpms/

#########################################################################################	
FROM nginx:alpine
#RUN mkdir /usr/share/nginx/html/rpms
COPY --from=build2 /rpms/ /usr/share/nginx/html/rpms/
COPY yum-repo/index.html /usr/share/nginx/html/
COPY yum-repo/nginx.conf /etc/nginx/conf.d/default.conf

pkg.list

docker-ce-19.03.4
docker-python 
docker-compose 
python-chardet 
python-requests
chrony audit rsync jq git tcpdump nc bind-utils net-tools ipvsadm graphviz

nginx.conf

server {
    listen 80;
    server_name localhost;
    location / {
        root /usr/share/nginx/html;
        index index.html;
        autoindex on;
    }
    
    error_page 500 502 503 504  /50x.html;
    location = 50x.html {
        root /usr/share/nginx/html;
    }
}

index.html

<!DOCTYPE html>
<html>
<head>
<title>Wise2C Yum Repo for Docker/K8S/Ceph/NFS installation</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Wise2C Yum Repo for Docker/K8S/Ceph/NFS installation</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>

<br />
<br />

<a href = "rpms" >Enter the RPM folder </a><br />

<br />
<br />

<p><em>Please create the file wise2c.repo as below and then move to /etc/yum.repos.d/</em></p>

<script type="text/javascript">
  var ip = location.host;
  var comment = "###############################################";
  document.write(comment.fontcolor("Red"));
  document.write("<pm><em></em></p>");
  document.write("[wise2c]"+"<br>");
  document.write("name=wise2c"+"<br>");
  document.write("baseurl=http://"+(ip)+"/rpms"+"<br>");
  document.write("enabled=1"+"<br>");
  document.write("gpgcheck=0"+"<br>");
  document.write("<pm><em></em></p>");
  document.write(comment.fontcolor("Red"));
</script>

</body>
</html>


猜你喜欢

转载自blog.51cto.com/14012942/2445905