在构建 docker-compose 的镜像时使用 Alpine 的本地镜像而不是遗留存储库

时间:2021-02-09 19:45:38

标签: docker-compose alpine

使用docker-compose构建容器时,是否可以使用docker使用的本地仓库(镜像)?

我有一个本地镜像,我的兴趣是当我用docker-compose build构建容器时,apk是从本地镜像下载的,而不是从网上下载

示例。

如果使用 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

当使用 docker-compose build 部署容器时,我喜欢使用我的本地 alpine 存储库而不是 Alpine 的任何 Internet 镜像,例如:

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 个答案:

答案 0 :(得分:1)

您需要一个本地 Docker Registry

答案 1 :(得分:1)

阅读 alpine docs Alpine Linux package management 后,我得到了使用本地镜像的静态 IP 的解决方案。我尝试使用主机名的名称 (repoalpine.test),但我找不到如何在 docker 网络上公开主机名。

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

现在工作

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
...