skip to Main Content

Is it possible to use a local repository (mirror) that is used by docker when building a container with docker-compose?

I have a local mirror, and my interest is that when I build a container with docker-compose build, the apk is downloaded from the local mirror, instead of the Internet

Example.

If a local deploy with Dockerfile

FROM alpine:3.13

# Install packages and remove default server definition
RUN apk --no-cache add php8=8.0.2-r0 php8-fpm php8-opcache php8-mysqli php8-json 
    php8-openssl php8-curl php8-soap php8-zlib php8-xml php8-phar php8-intl php8-dom php8-xmlreader php8-ctype 
    php8-session php8-simplexml php8-mbstring php8-gd nginx supervisor curl php8-exif php8-zip php8-fileinfo 
    php8-iconv php8-soap tzdata htop mysql-client php8-pecl-imagick php8-pecl-redis php8-tokenizer php8-xmlwriter 
    nano && rm /etc/nginx/conf.d/default.conf

When deploy container with docker-compose build I like that use my local repository of alpine instead any internet mirrors of Alpine such:

fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/community/x86_64/APKINDEX.tar.gz
(1/124) Installing ca-certificates (20191127-r5)
(2/124) Installing brotli-libs (1.0.9-r3)
(3/124) Installing nghttp2-libs (1.42.0-r1)
...

2

Answers


  1. Chosen as BEST ANSWER

    After read alpine docs Alpine Linux package management I get solution using static IP of local mirror. I tried to use the name of the hostname (repoalpine.test) but I couldn't find how to make the hostname public on the docker network.

    RUN apk --no-cache -X http://172.20.0.254/v3.13/main -X http://172.20.0.254/v3.13/community 
        add php8=8.0.2-r0 php8-fpm php8-opcache php8-mysqli php8-json 
        php8-openssl php8-curl php8-soap php8-zlib php8-xml php8-phar php8-intl php8-dom php8-xmlreader php8-ctype 
        php8-session php8-simplexml php8-mbstring php8-gd nginx supervisor curl php8-exif php8-zip php8-fileinfo 
        php8-iconv php8-soap tzdata htop mysql-client php8-pecl-imagick php8-pecl-redis php8-tokenizer php8-xmlwriter 
        nano && rm /etc/nginx/conf.d/default.conf
    

    Now work

    Step 7/22 : RUN apk --no-cache -X http://172.20.0.254/v3.13/main -X http://172.20.0.254/v3.13/community     add php8=8.0.2-r0 php8-fpm php8-opcache php8-mysqli php8-json     php8-openssl php8-curl php8-soap php8-zlib php8-xml php8-phar php8-intl php8-dom php8-xmlreader php8-ctype     php8-session php8-simplexml php8-mbstring php8-gd nginx supervisor curl php8-exif php8-zip php8-fileinfo     php8-iconv php8-soap tzdata htop mysql-client php8-pecl-imagick php8-pecl-redis php8-tokenizer php8-xmlwriter     nano && rm /etc/nginx/conf.d/default.conf
     ---> Running in 4f2c6521e6e6
    fetch http://172.20.0.254/v3.13/community/x86_64/APKINDEX.tar.gz
    ...
    

  2. You need a local Docker Registry

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search