Alpine Linux install package without internet (docker)
Asked Answered
S

2

9

I'm trying to build a Docker image with Alpine and only need to install some packages (apk add) but without internet because our dev environment allows no internet connection. So I COPY the apk's in /temp and try to install from there. Like is written in the docs add local package But still it tries to get to the internet to fetch an index... I don't want that. Is that possible?

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"]

(and yes, this image is available on DockerHub, but we need to build it ourselves)

Selfassertion answered 4/12, 2018 at 20:16 Comment(0)
M
12

Yes, it is possible. It is some kind of hack :) Alpine package manager (apk) always needs a repository to index from, when it installs packages (apk add). But it is possible to provide it an empty list of repositories and define it during the install command (apk add --repositories-file=).

Dockerfile is:

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"]

And we get:

$ 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
Mcclimans answered 13/1, 2019 at 11:55 Comment(2)
Instead of creating an empty file, you can do apk add --repositories-file=/dev/nullSporophyll
Also, if any packages you give it depend on other packages you give it, apk will figure out the correct order to install them it, so you can just use *.apk and it will install it all in the correct orderSporophyll
O
0

As per the documentation on wiki.alpinelinux.org, you can simply use apk add --allow-untrusted /path/to/file.apk, and if you want multiple packages, apk add --allow-untrusted /path/to/file.apk /path/to/file_2.apk

Outrigger answered 28/6, 2022 at 20:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.