美文网首页Docker
【yum】用nginx镜像搭建局域网yum源

【yum】用nginx镜像搭建局域网yum源

作者: Bogon | 来源:发表于2019-05-20 22:22 被阅读40次

    一、实验环境

    # cat Dockerfile

    #############################################################

    FROM centos

    ENV NGINX_VERSION 1.16.0

    ENV BLUID_LIST  "gcc cpp glibc-devel glibc-headers kernel-headers libgomp libmpc mpfr make"

    RUN useradd -u 2019 test \

        && yum install -y ${BLUID_LIST} \

        && yum install -y createrepo net-tools \

        && mkdir /opt/tmp \

        && curl -kLo /opt/tmp/nginx.tgz https://github.com/nginx/nginx/archive/release-${NGINX_VERSION}.tar.gz \

        && tar -zxf /opt/tmp/nginx.tgz -C /opt/tmp/ \

        && cd /opt/tmp/nginx-release-${NGINX_VERSION} \

        && auto/configure --without-http_rewrite_module --without-http_gzip_module \

        && make && make install \

        && ln -sf /dev/stdout /usr/local/nginx/logs/access.log \

        && ln -sf /dev/stderr /usr/local/nginx/logs/error.log \

        && ln -sf /usr/local/nginx/sbin/nginx /usr/bin/nginx \

        && yum clean all \

        && rm -rf /var/cache/yum/*  /opt/tmp

    WORKDIR /home/test

    COPY --chown=test  docker-entrypoint.sh /usr/bin/

    COPY --chown=test  nginx.conf /usr/local/nginx/conf/nginx.conf

    RUN chmod 0700 /usr/bin/docker-entrypoint.sh

    ENTRYPOINT ["docker-entrypoint.sh"]

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

    ###############################################################

    # cat docker-entrypoint.sh

    ################################################################

    #!/bin/sh

    mkdir -p /opt/yum

    createrepo /opt/yum

    exec "$@"

    ################################################################

    # cat nginx.conf

    #################################################################

    user test;

    worker_processes  1;

    events {

        worker_connections 1024;

    }

    http {

        include            mime.types;

        default_type      application/octet-stream;

        sendfile          on;

        keepalive_timeout  65;

        server {

            listen        80;

            server_name    localhost;

            location / {

                root      /opt/yum;

                autoindex  on;

            }

            error_page    500 502 503 504 /50x.html;

            location = /50x.html {

                root  html;

            }

        }

    }

    #################################################################

    二、用Dockerfile打镜像


    # docker build  -f Dockerfile   -t   yumrepo:latest   .

    # docker images  

    三、用镜像起一个仓库容器

    # setenforce 0

    # sed  -i  's/^SELINUX=.*/SELINUX=permissive/g'  /etc/selinux/config

    # systemctl  stop firewalld

    # systemctl disable firewalld

    #  mkdir  /opt/yum  

    #  mv  *.rpm     /opt/yum

    # docker run  -it  -d    --name  LocalRepositry   -v  /opt/yum:/opt/yum  -p 80:80    yumrepo:latest

    # docker ps   -a  

    # docker logs   LocalRepositry 

    # ss  -tan  | grep  -w  ":80"

    浏览器访问  http://192.168.1.108

    四、参考

    yumRepo/Dockerfile

    https://github.com/cmp1234/yumRepo/blob/master/Dockerfile

    Linux > man-pages>repotrack

    http://man7.org/linux/man-pages/man1/repotrack.1.html

    How to download a software package with all dependencies and sub-dependencies?

    https://unix.stackexchange.com/questions/50642/download-all-dependencies-with-yumdownloader-even-if-already-installed

    What does set -e and exec “$@” do for docker entrypoint scripts?

    https://stackoverflow.com/questions/39082768/what-does-set-e-and-exec-do-for-docker-entrypoint-scripts

    相关文章

      网友评论

        本文标题:【yum】用nginx镜像搭建局域网yum源

        本文链接:https://www.haomeiwen.com/subject/axtrzqtx.html