简体   繁体   English

如何离线在 alpine linux 中安装.apk 文件?

[英]How can I install .apk file in alpine linux offline?

My docker image based on alpine Linex can not get anything from network.我的基于 alpine Linex 的 docker 图像无法从网络获取任何内容。 So the command "apk add xxx" is valid.所以命令“apk add xxx”是有效的。 Now my idea is downloading the.apk file and coping it into the docker container.现在我的想法是下载 .apk 文件并将其复制到 docker 容器中。 But how can I install the.apk file?但是我怎样才能安装.apk 文件呢?

Let's say you are trying to install glibc in Alpine假设您正在尝试在 Alpine 中安装 glibc

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然后,使用带有 --allow-untrusted 标志的 apk

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

Next steps are fine for me:接下来的步骤对我来说很好:

  1. Get an "online" Alpine machine and download packages.获取“在线”Alpine 机器并下载软件包。 Example is with "zip" and "rsync" packages:示例是“zip”和“rsync”包:

    • Update your system: sudo apk update更新您的系统: sudo apk update
    • Download only this packages: apk fetch zip rsync只下载这个包: 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.将此文件上传到“离线”Alpine 机器。

  4. Install apk packages:安装apk包:

    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更多信息: https://wiki.alpinelinux.org/wiki/Alpine_Linux_package_management

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.如果可以从连接到公共 Internet 的系统中运行 Docker 命令,则可以通过将图像分成两部分来以 Docker 原生方式执行此操作。

The first image only contains the apk commands, but no actual application code.第一个图像仅包含apk命令,但没有实际的应用程序代码。

FROM alpine
RUN apk add ...

Build that image docker build -t me/alpine-base , connected to the network.构建该图像docker build -t me/alpine-base ,连接到网络。

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.如果可以将某些系统连接到两个网络,并在环境中运行 Docker 注册表,那么您可以使用docker push将图像发送到隔离环境。 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.否则,这是您需要docker save的少数情况之一:创建图像的 tar 文件,将该文件移动到隔离环境中(通过堡垒主机,在 USB 密钥上,...),然后docker load它在目标系统上。

Now you have that base image on the target system, so you can install the application on top of it without calling apk .现在您在目标系统上拥有了该基础映像,因此您可以在其之上安装应用程序而无需调用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.如果您有类似应用程序的package.json / requirements.txt / Gemfile / go.mod之类的东西,它会列出所有应用程序的下载,但您可以提前安装库依赖项,如果这些依赖关系发生变化,需要记住重复它并手动移动更新的基础映像。

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.请注意,当您获取 apk 以下载所有依赖项时,标志 --recursive 是必需的,否则当您因缺少软件包而离线 go 时可能会收到错误消息。

  1. sudo apk update须藤apk更新
  2. sudo apk fetch --recursive packageName sudo apk fetch --recursive packageName
  3. transfer the files to the offline host将文件传输到离线主机
  4. sudo apk add --allow-untrusted <dependency.apk> sudo apk add --allow-untrusted <dependency.apk>
  5. sudo apk add --allow-untrusted <package.apk> sudo apk add --allow-untrusted <package.apk>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM