How can I install .apk file in alpine linux offline?
Asked Answered
A

4

9

My docker image based on alpine Linex can not get anything from network. So the command "apk add xxx" is valid. Now my idea is downloading the .apk file and coping it into the docker container. But how can I install the .apk file ?

Applicable answered 26/5, 2020 at 9:42 Comment(0)
A
6

Next steps are fine for me:

  1. Get an "online" Alpine machine and download packages. Example is with "zip" and "rsync" packages:

    • Update your system: sudo apk update
    • Download only this packages: apk fetch zip rsync
  2. You will get this files (or maybe an actual version):

    • zip-3.0-r8.apk
    • rsync-3.1.3-r3.apk
  3. Upload this files to the "offline" Alpine machine.

  4. Install apk packages:

    sudo apk add --allow-untrusted zip-3.0-r8.apk sudo apk add --allow-untrusted rsync-3.1.3-r3.apk

More info: https://wiki.alpinelinux.org/wiki/Alpine_Linux_package_management

Amylase answered 21/7, 2021 at 7:16 Comment(0)
I
5

Let's say you are trying to install glibc in Alpine

Download the packages into your current directory

wget "https://circle-artifacts.com/gh/andyshinn/alpine-pkg-glibc/6/artifacts/0/home/ubuntu/alpine-pkg-glibc/packages/x86_64/glibc-2.21-r2.apk"
wget "https://circle-artifacts.com/gh/andyshinn/alpine-pkg-glibc/6/artifacts/0/home/ubuntu/alpine-pkg-glibc/packages/x86_64/glibc-bin-2.21-r2.apk"

Then, use apk with --allow-untrusted flag

apk add --allow-untrusted glibc-2.21-r2.apk glibc-bin-2.21-r2.apk

And finish the installation (only needed in this example)

/usr/glibc/usr/bin/ldconfig /lib /usr/glibc/usr/lib
Innkeeper answered 26/5, 2020 at 9:49 Comment(2)
It is useful for me! Thanks a lot.Applicable
What if I want that apk package to be installed in a specific directory?Reimer
T
0

please note that the flag --recursive is necessary when you fetch your apk to download all the dependencies too, else you might get an error when you go offline for missing packages.

  1. sudo apk update
  2. sudo apk fetch --recursive packageName
  3. transfer the files to the offline host
  4. sudo apk add --allow-untrusted <dependency.apk>
  5. sudo apk add --allow-untrusted <package.apk>
Tilla answered 20/5, 2022 at 12:8 Comment(0)
S
-1

If it's possible to run Docker commands from a system that's connected to the public Internet, you can do this in a Docker-native way by splitting your image into two parts.

The first image only contains the apk commands, but no actual application code.

FROM alpine
RUN apk add ...

Build that image docker build -t me/alpine-base, connected to the network.

You now need to transfer that image into the isolated environment. If it's possible to connect some system to both networks, and run a Docker registry inside the environment, then you can use docker push to send the image to the isolated environment. Otherwise, this is one of the few cases where you need docker save: create a tar file of the image, move that file into the isolated environment (through a bastion host, on a USB key, ...), and docker load it on the target system.

Now you have that base image on the target system, so you can install the application on top of it without calling apk.

FROM me/alpine-base
WORKDIR /app
COPY . .
CMD ...

This approach will work for any sort of artifact. If you have something like an application's package.json/requirements.txt/Gemfile/go.mod that lists out all of the application's library dependencies, you can run the download-and-install step ahead of time like this, but you'll need to remember to repeat it and manually move the updated base image if these dependencies ever change.

Stressful answered 26/5, 2020 at 10:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.