我正在尝试使用Alpine构建Docker映像,并且只需要安装一些软件包(apk add
)但没有互联网,因为我们的开发环境不允许互联网连接。
因此,我在/ temp中复制了apk并尝试从那里安装。像是写在文档add local package中
但是它仍然试图通过互联网获取索引...我不想要那样。
有可能吗?
FROM alpine:3.8
COPY ./apk/* /tmp/
RUN apk add --allow-untrusted --no-network --no-cache /tmp/ca-certificates-20171114-r3.apk /tmp/libcurl-7.61.1-r1.apk /tmp/libssh2-1.8.0-r3.apk /tmp/nghttp2-libs-1.32.0-r0.apk /tmp/curl-7.61.1-r1.apk
ENTRYPOINT ["/usr/bin/curl"]
(是的,该映像在DockerHub上可用,但我们需要自己构建它)
谢谢!
关于, 耶罗恩
答案 0 :(得分:2)
是的,有可能。这是一种黑客:) Alpine软件包管理器(apk
)在安装软件包(apk add
)时始终需要一个存储库以进行索引。但是可以为它提供一个空的存储库列表,并在安装命令(apk add --repositories-file=
)中对其进行定义。
Dockerfile
是:
FROM alpine:3.8
COPY ./apk/* /tmp/
RUN touch repo.list && apk add --repositories-file=repo.list --allow-untrusted --no-network --no-cache /tmp/ca-certificates-20171114-r3.apk /tmp/libcurl-7.61.1-r1.apk /tmp/libssh2-1.8.0-r3.apk /tmp/nghttp2-libs-1.32.0-r0.apk /tmp/curl-7.61.1-r1.apk
ENTRYPOINT ["/usr/bin/curl"]
然后我们得到:
$ docker build . --no-cache
Sending build context to Docker daemon 663kB
Step 1/4 : FROM alpine:3.8
---> 11cd0b38bc3c
Step 2/4 : COPY ./apk/* /tmp/
---> 31248015db45
Step 3/4 : RUN touch repo.list && apk add --repositories-file=repo.list --allow-untrusted --no-network --no-cache /tmp/ca-certificates-20171114-r3.apk /tmp/libcurl-7.61.1-r1.apk /tmp/libssh2-1.8.0-r3.apk /tmp/nghttp2-libs-1.32.0-r0.apk /tmp/curl-7.61.1-r1.apk
---> Running in b8d214219e03
(1/5) Installing ca-certificates (20171114-r3)
(2/5) Installing nghttp2-libs (1.32.0-r0)
(3/5) Installing libssh2 (1.8.0-r3)
(4/5) Installing libcurl (7.61.1-r1)
(5/5) Installing curl (7.61.1-r1)
Executing busybox-1.28.4-r0.trigger
Executing ca-certificates-20171114-r3.trigger
OK: 6 MiB in 18 packages
Removing intermediate container b8d214219e03
---> 3e36700c3641
Step 4/4 : ENTRYPOINT ["/usr/bin/curl"]
---> Running in 32abd512c88e
Removing intermediate container 32abd512c88e
---> bd915c91c7ec
Successfully built bd915c91c7ec