Alpine linux apt get

Introduction

featured image

Web applications have come a long way, and so have the services that host them. One of the most popular ones now is Docker. The concept of sandboxed containers for web applications gives so much more accessibility and control. However, when you’re just starting out on using Docker, it might take some time to get used to. Usually, when building images for Docker using a Dockerfile, you might run into the following error:

Which is why in this article, I will help you cure this error and get your docker image up and running in minutes.

You’re using the wrong command

Yes. In fact, it is most probably the case for which you have faced the issue. C’mon Sarker! What are you saying?

As it appears to be, it is common to confuse the package manager of Debian-based distributions (such as Ubuntu), with the package manager of Alpine Linux. Alpine Linux is the go-to distribution for use in docker containers. And if you happen to follow any online tutorials on using Docker for setting up your containers, it is very much possible that you had used the alpine linux image (without realizing it) and are now trying to use the package manager of some other distribution.

In Alpine Linux, the package manager is called apk, while in Debian-based distributions like Ubuntu, the package manager is called apt. If you now try to use apt inside an alpine linux container (or inside a Dockerfile defined with alpine), you’d get the error message.

So basically, there are two main fixes for this. The first is to use the right package manager for your container, without changing the distribution, and the other option is to entirely change the distribution to something like Ubuntu, so it no longer bothers you. The following sections will discuss them in detail.

Use the right package manager

If you are fine with using a new package manager for your system that you’re not used to, it’s best to simply just learn it. If you had selected alpine linux when building your image, you need to use the apk package manager. The base differences of it from the apt or the apt-get commands in Ubuntu are as follows:

  1. When trying to update and upgrade the system, you’d use the following command:

There are a few other differences, but these are the ones you’d mostly need to use on a daily basis. So try to stick with it (if you wish to use docker containers that are lightweight).

Dockerfile example

In case you’re using a Dockerfile defined with alpine linux, you need to make sure that you use apk if you include anything that relates to the package manager instead of using apt. For example, if you wish to include lines in your Dockerfile such as one which updates the image when being built as well as another one which installs a given package, it should look something like this:

FROM alpine:latest RUN apk update && apk upgrade RUN apk add

Using Ubuntu Image in Docker

Directly install and run a container with Ubuntu

If you have decided that the apk package manager is not your thing, and would like to go back to your old, lovely distro (Ubuntu, most probably – why are you reading this if it’s not?) then you can consider building a new image with Ubuntu. If you don’t wish to use a docker file and would like to jump straight in, simply run the following line of command in your terminal (make sure that the docker daemon is running, otherwise you’d encounter another weird error message):

$ sudo docker run -it ubuntu:latest

This command will pull in the latest version of ubuntu from the docker repositories and will create an image for you to run. Once the download is finished, it’ll take you straight inside the container with a totally isolated filesystem. Inside here, you can now do anything you might have wished to do with your container. Why not start by running “apt-get update”? (Chill out. You won’t be seeing the error message this time around!)

Читайте также:  Acronis true image linux based

Install Ubuntu using a Dockerfile

If you’ve got a good grasp of creating Dockerfiles (even if you don’t, I bet it’s simpler than you may have thought), I’d recommend you to use a Dockerfile to build your image. What this will allow you is that everytime you want to build containers with the same configuration and pre-installation procedures, it will save you a ton of time.

First up, create a file with the exact name “Dockerfile” using the text editor of your choice and store it inside a recognisable folder. Then, you need to include the code (or plainly, some instructions) which will build the Ubuntu image. A very basic Dockerfile to build an Ubuntu image should look like this:

FROM ubuntu:latest RUN apt-get update && apt-get upgrade RUN apt-get install

Save and then exit the file. Now while you’re inside the same directory where the Dockerfile is located, run the following command to build the image:

Replace with anything you like, but you’d probably want it to be short and simple, so it is easy to type for when you want to run the container at a later time.

Once the downloading is over, and all the commands have successfully been executed from the Dockerfile, your image will be built, and you can verify it by running:

You should see a new entry with the name you gave the image, including an Image ID.

To now run and enter your newly created container (Ahh, Ubuntu! Where have you been?), simply use the following command:

Источник

How to get the source code used to build the packages of the base alpine linux docker image?

Why I want to know this: Currently, I use apt-get source to get the source code for all packages within my Debian based docker images to comply with the GPL when I distribute the docker images. Now there are e few docker images where I would like to use the alpine based docker image but I don’t know how to get the source code used to build the packages within these docker images. What I found out so far: If there were an equivalent for apt-get source for alpine linux this wouldn’t be a problem (the documentation does not mention a source option for apk) The Github page only contains the scripts and patches but not the exact source code, but then the build scripts just seem to get the source code from upstream. They have to provide the source code somewhere since they are surely distributing some GPL licensed binaries within there docker images. How to get (exactly) the source code used to build the packages of an alpine docker image?

Читайте также:  Check link speed linux

1 Answer 1

Alpines package manager APK has no equivalent to the dpkg source command ( apt-get source ).

To get the exact source code matching the installed packages on alpine linux you can use a combination of apk and alpine-sdk commands.

Steps to get the exact source code of the installed packages on alpine linux:

    Get a list of all installed packages:

git clone --depth 1 --branch v3.13.1 git://git.alpinelinux.org/aports 
  1. (Optional) you can set a custom destination for the source files with export SRCDEST=»/path/to/my/custom/src/destination» otherwise a src folder within the current package folder will be created
  2. Within the folder matching the package name (e.g. aports/main/git for the git package) run abuild -F fetch verify as root or abuild fetch verify as a normal user (this will fetch the source files referenced in the APKBUILD script)
  3. Packages that contain GPL licensed code: To comply with the GPL you have to provide the fetched source files and the APKBUILD script itself. You also have to provide the source files and APKBUILD script for packages listed in the makedepends variable of the APKBUILD script (most of the time these packages e.g. openssl-dev are sub-packages (see point 6) of the runtime dependencies e.g. openssl ) see this question about GPL and build dependencies.

Источник

13 Apk Commands for Alpine Linux Package Management

Alpine Linux is an independent, free, and open-source Linux distribution based on BusyBox and musl. It is a lightweight and security-oriented Linux distribution that comes in a small footprint (about 160 MB).

For this reason, it’s widely used in creating containers that are lightweight and standalone units that provide an isolated environment to deploy and run applications.

Alpine Linux targets users who desire simplicity, security, and efficient resource utilization. It is designed for x86, x86-64. AArch64 and ARM architectures.

Like any other Linux distribution, Alpine Linux comes with its own package manager known as apk (Alpine Package Keeper) and comes pre-installed on all Alpine Linux distributions.

Apk handles all the package management operations including searching, installing, upgrading, listing, and removing software packages just to mention a few. In this guide, we showcase commonly used Apk command examples in Alpine Linux.

Alpine Linux Packages and Repositories

Before we look at the various apk commands that you can leverage to manage your packages, let us touch on Alpine Linux repositories.

Alpine Linux has two repositories enabled by default: the main and community repositories.

  1. The main repository comprises packages that are rigorously tested and approved to be officially hosted by the Alpine Linux core development team.
  2. The community repository, on the other hand, comprises community-supported packages which are ported from the edge or testing repositories.

On your local Alpine Linux system, you can find the repositories in the /etc/apk/repositories file, you can use the cat command to view them as follows.

Alpine Linux Repositories

Having looked at the repositories, let us straight away jump into managing packages using the apk package manager.

1. Update Alpine Linux

To update the repositories and package lists on Alpine Linux, run the command

Читайте также:  Получить значение переменной окружения linux

Alpine Linux Update

2. Search for an Availability of Packages

Before installing packages, it’s worthwhile to check if the packages have been officially been hosted in the repositories. To do so, use the syntax:

For example, to search for a nano package in the repositories, run the command:

Search Package in Alpine Linux

3. Get a Description of an Installed Package

To get a description of a package in the repositories, about the package pass the -v and -d flags as shown. The option -d is short for description whilst the -v option prints out verbose output.

Get Package Description in Alpine Linux

4. Install Packages in Alpine Linux

To install packages on Alpine Linux, use the syntax:

For example, to install the nano text editor, run the command:

Install Packages in Alpine Linux

Additionally, you can install multiple packages in a single command using the syntax:

$ apk add package1 package2

For example, the command below installs neofetch and vim editor at a go.

Install Multiple Packages in Alpine Linux

You can confirm if you installed neofetch by running the command:

This populates information about the operating system such as OS type, kernel, uptime, and underlying hardware such as CPU and memory.

Neofetch Show Linux Information

To confirm that vim editor is installed, simply run the vim command without any arguments and this will display information about vim.

Vim Editor Info

The -i option prompts for user interaction when installing packages. It causes apk to ask you whether to continue with the installation of the package or abort.

Install Package Confirmation

5. Check Installed Package in Alpine Linux

To probe if a certain package is already installed, use the syntax:

In this example, we are checking if Nano is installed.

In addition, you can check if multiple packages exist by listing them in the same line. For this example, we are verifying if both nano and vim are installed.

Check Package in Alpine Linux

To list additional information such as the version and size of the installed package simply run:

Check Package Information in Alpine Linux

6. List Files Associated with a Package

The -L flag allows you to list the files associated with a package, which includes the binary and configuration files and other files.

List Installed Package Files in Alpine Linux

7. List Dependencies of a Package

With the -R option, you can list the packages that the package depends on. In the following example, we are listing the dependencies that vim depends on.

List Package Dependencies in Alpine Linux

8. Find the Installed Size of a Package

To view the installed size of a package, use the -s option (lowercase) as follows:

Find Installed Package Size in Alpine Linux

9. List All Installed Packages

To list all installed packages on Alpine Linux, run the command:

List All Installed Packages in Alpine Linux

10. Upgrade Alpine Linux

To upgrade all the packages on Alpine Linux to their latest versions, run the command

Upgrade Alpine Linux

To perform a dry run of the upgrade, pass the -s option. This merely runs a simulation and shows the versions that the packages will be upgraded to. It does not upgrade the packages.

Dry Run Alpine Linux Upgrade

11. Hold a Package Upgrade

There are instances where you may want to keep a few packages back from an upgrade. For instance to keep nano in its current version – nano-5.9-r0 – run the command.

Hold Package Upgrade in Alpine Linux

This will exempt the nano package from the upgrade as other packages are upgraded to their latest versions.

To later release the package for the upgrade, run:

12. Remove a Package in Alpine Linux

If you no longer require a package, you can remove it using the syntax:

For example, to delete vim, run the command.

Remove Packages in Alpine Linux

13. Getting Help with Apk Command

For additional apk commands, you can browse the apk help catalog as shown

Apk Command Help

In this guide, we focussed on Alpine apk command examples. We hope that this will help you as you get started installing and managing packages on Alpine Linux.

Источник

Оцените статью
Adblock
detector