- Alpine Linux (for Docker images) #226
- Comments
- markrendle commented Jul 15, 2016 •
- installing openssl-dev and openldap-dev in alpine:3.6 not possible due to unsatisfiable contstraints #303
- Comments
- sebastianhutter commented Jul 6, 2017
- andyshinn commented Jul 6, 2017
- sebastianhutter commented Jul 7, 2017
- ghost commented Oct 10, 2017
- sebastianhutter commented Oct 10, 2017
- ghost commented Oct 11, 2017
- 10 Alpine Linux apk Command Examples
- Purpose
- Syntax
- Alpine Linux apk command examples
- How to update the package list
- How to search for package(s)
- To list all packages available, along with their descriptions
- How do I search package by wildcards?
- How to install a package(s) by name
- Interactive install or upgrade
- Simulation with apk command
- How to hold a specific package back and not upgrade it
- How do install a local .apk file package?
- How to remove or delete a package(s) by name
- How do I delete old packages caches on Alpine Linux?
- How to upgrade running Alpine Linux
- How do I upgrade selected packages only?
- How do I list installed packages?
- Find out which package a file belongs to..
- List contents of the PACKAGE
- Check if PACKAGE is installed
- List packages that the PACKAGE depends on
- List all packages depending on PACKAGE
- Show installed size of PACKAGE
- Print description for PACKAGE
- Print all information about PACKAGE
- How do I see statistics about repositories and installations?
- apk command options and examples
- See also
- Alpine Linux package management
- Contents
- Overview
- Packages and Repositories
- Repository pinning
- Commandline repository options
- Update the Package list
- Add a Package
- Add a local Package
- Remove a Package
- Upgrade a Running System
- Packages in general
- Upgrading «diskless» and «data» disk mode installs
- Search for Packages
- Information on Packages
- apk info
- Listing installed packages
- apk policy
- Additional apk Commands
- Local Cache
- Overview
- Enabling Local Cache with current releases
- Cache maintenance
- Removing older packages
- Download missing packages
- Delete and download in one step
- Automatically Cleaning Cache on Reboot
- Special Caching Configurations
- Enabling Local Cache on HDD installs
- Local Cache on tmpfs volumes
- Manually Enabling Local Cache (required for releases prior to v2.3)
- Advanced APK Usage
- Holding a specific package back
- Troubleshooting
- «apk-tools is old»
Alpine Linux (for Docker images) #226
Comments
markrendle commented Jul 15, 2016 •
Support for Alpine Linux has been mentioned in the past on various repositories. It’s desirable because the Docker image for Alpine is under 5MB in size, compared to over 100MB for Debian 8, which is the current base for the dotnet images. Docker are looking to migrate all their official library images to Alpine.
The blocker for .NET Core has been the availability of the core dependencies on Alpine, of which the last outstanding one was LTTng, which is now in the APK testing repository for Alpine 3.5.
I’m not an expert on building .NET Core, CLI, etc, but if anybody fancies having a go at creating an Alpine build, it should be possible.
Looking at the Linux build instructions for CoreCLR, all the APT packages mentioned are available now, at least in Alpine’s edge/testing repository, if not in edge/main:
APT | APK |
---|---|
cmake | cmake |
llvm-3.5 | llvm |
clang-3.5 | clang (appears to be 3.8) |
lldb-3.6 | lldb (in edge/testing) |
lldb-3.6-dev | lldb-dev (in edge/testing) |
libunwind8 | libunwind (in edge/main) |
libunwind8-dev | libunwind-dev (in edge/main) |
gettext | gettext |
libicu-dev | icu-dev |
liblttng-ust-dev | lttng-ust-dev (in edge/testing) |
libcurl4-openssl-dev | curl-dev |
libssl-dev | openssl-dev |
uuid-dev | util-linux-dev (seems to be where the uuid.h file lives) |
And here’s a list of the deps from the dotnet image with their Alpine equivalents.
APT package | APK package |
---|---|
libc6 | libc6-compat |
libcurl3 | libcurl |
libgcc1 | libgcc |
libgssapi-krb5-2 | krb5-libs |
libicu52 | icu-libs |
liblttng-ust0 | lttng-ust-dev |
libssl1.0.0 | libssl1.0 |
libstdc++6 | libstdc++ |
libunwind8 | libunwind |
libuuid1 | libuuid |
zlib1g | zlib |
Right, this is where somebody points out that the only reason these dependencies have made it into Alpine is that a .NET Core team member ported them all, for precisely this reason, and I’ve wasted the time spent on this issue. 😞
The text was updated successfully, but these errors were encountered:
Источник
installing openssl-dev and openldap-dev in alpine:3.6 not possible due to unsatisfiable contstraints #303
Comments
sebastianhutter commented Jul 6, 2017
Installation of openssl-dev and openldap-dev in alpine:3.6 and alpine:3.5 is not possible due to unsatisfiable contstraints:
this works in alpine:3.4:
I assume some dependencies in the APK repository are off. Any ideas to circumvent this issue?
The text was updated successfully, but these errors were encountered:
andyshinn commented Jul 6, 2017
This sounds like openldap is built against libressl instead of openssl in 3.6. You cannot install both openssl-dev and libressl-dev in 3.6. What are you needing openssl-dev for? Depending on what you are building, libressl-dev may be able to replace openssl-dev .
sebastianhutter commented Jul 7, 2017
i need compile nginx from source with ssl and ldap.
libressl-dev did the trick. thanks a lot for pointing this out!
ghost commented Oct 10, 2017
I do have the same problem. And libressl-dev does not do the trick 🙁
sebastianhutter commented Oct 10, 2017
@juliengk what are you trying to build which causes trouble? can you post your dockerfile / commands?
ghost commented Oct 11, 2017
I have tried again to replace openssl-dev with libressl-dev and that worked. When building the docker image, some python packages are installed and so was complaining about the missing lib. I have updated the version of the python packages and all is good now.
Thanks and sorry for disturbing for nothing
Источник
10 Alpine Linux apk Command Examples
I am new Alpine Linux system admin user. How do I use apk command line utility for the package management on Apline Linux server running in cloud or a Linux container? How can I use the apk command for the package management?
apk command details | |
---|---|
Description | APK command |
Category | Package Manager |
Difficulty | Easy |
Root privileges | Yes |
Est. reading time | 10 minutes |
Table of contents
|
Purpose
Use apk for installing, upgrading, configuring, and removing apps/programs for an Alpine Linux operating system in a consistent manner.
Syntax
The basic syntax is as follows:
apk [options] command
apk [options] command pkgName
apk [options] command pkgName1 pkgName2
Alpine Linux apk command examples
Let us see how to use the apk command to install security updates or new set of packages on an Alpine Linux server.
How to update the package list
To update your package list, enter:
# apk update
Sample outputs:
Fig.01: How to update the package list in Alpine Linux
How to search for package(s)
The syntax is:
# apk search pkgName
For example, search a package named htop, run:
# apk search htop
Sample outputs:
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
To search and display description:
# apk search -v -d ‘htop’
Sample outputs:
To list all packages available, along with their descriptions
# apk search -v
Sample outputs:
How do I search package by wildcards?
The syntax is as follows to search all php7 packages or php5 packages:
# apk search -v ‘php5*’
### OR ###
# apk search -v ‘php7*’
Sample outputs:
How to install a package(s) by name
The syntax is:
# apk add pkgName
# apk add pkgName1 pkgName2
To install a htop package, run:
# apk add htop
Sample outputs:
To install Apache2 along with PHP7 and modules, run:
# apk add apache2 php7-apache2 php7-gd php7-mysqli
Sample outputs:
Interactive install or upgrade
We can force confirmation before performing certain operations by passing the -i option:
# apk -i add nginx
# apk -i upgrade
Simulation with apk command
We can simulate the requested operation without making any changes. Helpful to see what packages will be upgrades or what will be done on the Alpine Linux system:
# apk -s command
# apk -s add nginx
# apk -s upgrade
In other words, nothing was installed or upgraded on the system, but you will know precisely what apk was about to do.
How to hold a specific package back and not upgrade it
If you want to upgrade Alpine Linux system, but keep or hold a specific package add version number. For instance, to hold the bash package to the version 5.0.0-r0 level or lower, run:
# apk add bash = 5.0.0-r0
One can do regex based version matching to hold the version to a major/minor release. For example:
# apk add bash =
How do install a local .apk file package?
The syntax is as follows to add a local package named foo.apk:
# apk add —allow-untrusted /path/to/foo.apk
apk add —allow-untrusted pkg1.apk pkg2.apk
How to remove or delete a package(s) by name
The syntax is:
# apk del pkgName
# apk del pkgName1 pkgName2
To delete a htop package run:
# apk del htop
Sample outputs:
How do I delete old packages caches on Alpine Linux?
To remove out older versions of packages, run the clean command as follows:
# apk cache clean
## or ##
# apk -v cache clean
One can also clean cache and download missing packages in one step:
# apk cache -v sync
How to upgrade running Alpine Linux
The syntax is:
# apk update && apk upgrade
You can create a bash shell alias as follows in
/.bashrc
# echo «alias update=’apk update && apk upgrade'» >> /.bashrc
Run it as follows:
# update
How do I upgrade selected packages only?
The syntax is
# apk add -u pkgName
To upgrade a htop only package:
# apk update
# apk add -u htop
How do I list installed packages?
The syntax is:
# apk info
# apk info -vv | grep ‘foo’
# apk info -vv | sort
Fig.02: How do I show/list installed packages in Alpine Linux
Find out which package a file belongs to..
to determine which package a file named /etc/passwd or /sbin/apk belongs to:
# apk info —who-owns /etc/passwd
/etc/passwd is owned by alpine-baselayout-3.0.4-r0
# apk info —who-owns /sbin/apk
/sbin/apk is owned by apk-tools-2.6.8-r2
List contents of the PACKAGE
# apk -L info pkgName
# apk -L info htop
Sample outputs:
Check if PACKAGE is installed
# apk -e info pkgName
#############################################
### find out if atop PACKAGE is installed ###
#############################################
# apk -e info atop
No output displayed if PACKAGE is NOT installed.
List packages that the PACKAGE depends on
# apk -R info atop
# apk -R info atop
Sample outputs:
List all packages depending on PACKAGE
# apk info -r pkgName
# apk info -r bash
Sample outputs:
Show installed size of PACKAGE
# apk info -s pkgName
# apk info -s atop
Sample outputs:
Print description for PACKAGE
# apk info -d pkgName
# apk info -d bash
Sample outputs:
Print all information about PACKAGE
# apk info -a pkgName
# apk info -a bash
Sample outputs:
How do I see statistics about repositories and installations?
Run the command:
# apk stats
Sample outputs:
apk command options and examples
Command | Usage | Example |
---|---|---|
apk update | Update the package list | apk update |
apk upgrade | Upgrade the system | apk update apt ugrade |
apk add pkg | Add a package | apk add apache |
apk del pkg | Delete a package | apk del nginx |
apk search -v | Search for packages | apk search -v apk search -v -d ‘nginx* ‘ apk search -v ‘apache*’ |
apk info | List all installed pacakges | apk info |
apk fix | Repair package or upgrade it without modifying main dependencies | apk fix |
apk policy pkg | Show repository policy for packages | apk policy bash |
apk stats | Show statistics about repositories and installations | apk stats |
See also
You learned about apk command and everyday examples to add, remove and manage packages on Alpine Linux. See also:
- /etc/apk/repositories file.
- apk man page
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Источник
Alpine Linux package management
Contents
Because Alpine Linux is designed to run from RAM, package management involves two phases:
- Installing / Upgrading / Deleting packages on a running system.
- Restoring a system to a previously configured state (e.g. after reboot), including all previously installed packages and locally modified configuration files. (RAM-Based Installs Only)
apk is the tool used to install, upgrade, or delete software on a running system.
lbu is the tool used to capture the data necessary to restore a system to a previously configured state.
This page documents the apk tool — See the Alpine Local Backup page for the lbu tool.
Overview
The apk tool supports the following operations:
add | Add new packages or upgrade packages to the running system |
del | Delete packages from the running system |
fix | Attempt to repair or upgrade an installed package |
update | Update the index of available packages |
info | Prints information about installed or available packages |
search | Search for packages or descriptions with wildcard patterns |
upgrade | Upgrade the currently installed packages |
cache | Maintenance operations for locally cached package repository |
version | Compare version differences between installed and available packages |
index | create a repository index from a list of packages |
fetch | download (but not install) packages |
audit | List changes to the file system from pristine package install state |
verify | Verify a package signature |
dot | Create a graphviz graph description for a given package |
policy | Display the repository that updates a given package, plus repositories that also offer the package |
stats | Display statistics, including number of packages installed and available, number of directories and files, etc. |
manifest | Display checksums for files contained in a given package |
Packages and Repositories
Software packages for Alpine Linux are digitally signed tar.gz archives containing programs, configuration files, and dependency metadata. They have the extension .apk , and are often called «a-packs».
The packages are stored in one or more repositories. A repository is simply a directory with a collection of *.apk files. The directory must include a special index file, named APKINDEX.tar.gz to be considered a repository.
The apk utility can install packages from multiple repositories. The list of repositories to check is stored in /etc/apk/repositories , one repository per line. If you booted from a USB stick ( /media/sda1 ) or CD-ROM ( /media/cdrom ), your repository file probably looks something like this:
Contents of /etc/apk/repositories
In addition to local repositories, the apk utility uses busybox wget to fetch packages using http:, https: or ftp: protocols. The following is a valid repository file:
Contents of /etc/apk/repositories
Repository pinning
You can specify additional «tagged» repositories in /etc/apk/repositories :
Contents of /etc/apk/repositories
After which you can «pin» dependencies to these tags using:
apk add stableapp newapp@edge bleedingapp@testing
Apk will now by default only use the untagged repositories, but adding a tag to specific package:
1. will prefer the repository with that tag for the named package, even if a later version of the package is available in another repository
2. allows pulling in dependencies for the tagged package from the tagged repository (though it prefers to use untagged repositories to satisfy dependencies if possible)
Commandline repository options
By default, the apk utility will use the system repositories for all operations. This behavior can be overridden by the following options:
—repositories-file REPOFILE | Override the system repositories by specifying a repositories file. |
-X|—repository REPO | Specify a supplemental repository that will be used in addition to the system repositories. This option can be provided multiple times. |
Update the Package list
Remote repositories change as packages are added and upgraded. To get the latest list of available packages, use the update command. The command downloads the APKINDEX.tar.gz from each repository and stores it in the local cache, typically /var/cache/apk/ , /var/lib/apk/ or /etc/apk/cache/ .
Adding the —update-cache , or for short -U switch to another apk command, as in apk —update-cache upgrade or apk -U add . , the command has the same effect as first running apk update before the other apk command.
Add a Package
Use add to install packages from a repository. Any necessary dependencies are also installed. If you have multiple repositories, the add command installs the newest package.
apk add openssh apk add openssh openntp vim
If you only have the main repository enabled in your configuration, apk will not include packages from the other repositories. To install a package from the edge/testing repository without changing your repository configuration file, use the command below. This will tell apk to use that particular repository.
Add a local Package
To install a locally available apk package, for example if this device has no internet access but you can upload apk packages directly to it, use the —allow-untrusted flag:
apk add —allow-untrusted /path/to/file.apk
Note that multiple packages can be given. When installing a local package, all dependencies should also be specified. For example:
apk add —allow-untrusted /var/tig-2.2-r0.apk /var/git-2.11.1-20.apk
Remove a Package
Use del to remove a package (and dependencies that are no longer needed.)
apk del openssh apk del openssh openntp vim
Upgrade a Running System
Packages in general
To get the latest security upgrades and bugfixes available for the installed packages of a running system, first update the list of available packages and then upgrade the installed packages:
apk update apk upgrade
Or, combining the same into one single command:
Here is an example, showing the procedure on a system that has several additional repositories pinned:
To upgrade only specific packages, use the -u or —upgrade option of the add command:
apk update apk add —upgrade busybox
To enable unattended, automatic upgrades of packages, see the apk-autoupdate package.
To upgrade to a newer release, refer to the corresponding release notes and Upgrading_Alpine.
Upgrading «diskless» and «data» disk mode installs
If booting a «diskless» system from a read-only device, or iso image on writable media, it’s not possible to update the boot files (kernel, modules, firmware, . ) that reside on that device.
It becomes possible to update the boot files, though, if using a boot device that is writable and has been prepared with setup-bootable .
However, even then, the kernel, with its modules and firmware files, can still not be updated directly through regular packages updates. Instead, there is the update-kernel script that can generate initfs images and install them together with upgraded kernels.
Upgrading can be done as follows.
apk add mkinitfs
This package is required for the generation of the initial filesystem used during boot.
- Additional initfs features that are missing in the default configuration, like the «btrfs» filesystem support (at the time of writing, to allow loading .apkovl configs and package cache during boot), may be enabled in /etc/mkinitfs/mkinitfs.conf .
- Available initfs features may be listed with ls /etc/mkinitfs/features.d
ls /etc/mkinitfs/features.d apk add nano nano /etc/mkinitfs/mkinitfs.conf lbu commit
Finally update the kernel and its boot environment.
- An update-kernel run needs at least 8 GB free ram memory to avoid a broken modloop-image.
- See update-kernel —help for options to manually add additional module or firmware packages.
Search for Packages
The search command searches the repository Index files for installable packages.
The return format is Package—Version. Omit Version for apk add Package
- To list all packages available, along with their descriptions:
To list all packages are part of the ACF system:
apk search -v ‘acf*’
To list all packages that list NTP as part of their description, use the -d or —description option:
apk search -v —description ‘NTP’
Information on Packages
apk info
The info command provides information on the contents of packages, their dependencies, and which files belong to a package.
For a given package, each element can be chosen (for example, -w to show just the webpage information), or all information displayed with the -a command.
apk info -a zlib
As shown in the example you can determine
- The description of the package (-d or —description)
- The webpage where the application is hosted (-w or —webpage)
- The size the package will require once installed (in bytes) (-s or —size)
- What packages are required to use this one (depends) (-R or —depends)
- What packages require this one to be installed (required by) (-r or —rdepends)
- The contents of the package, that is, which files it installs (-L or —contents)
- Any triggers this package sets. (-t or —triggers) Listed here are directories that are watched; if a change happens to the directory, then the trigger script is run at the end of the apk add/delete. For example, doing a depmod once after installing all packages that add kernel modules.
apk info —who-owns /sbin/lbu
Listing installed packages
To list all installed packages, use:
To list all installed packages in alphabetical order, with a description of each, do:
apk policy
To display the repository a package was installed from and will be updated from, plus any tagged or enabled repositories where it is also offered, if any, for this architecture — its policy:
Additional apk Commands
Local Cache
Overview
To have the packages available during boot, apk can keep a cache of installed packages on a local disk.
Added packages can then be automatically (re-)installed from local media into RAM when booting, without requiring, and even before there is a network connection.
The cache can be stored on any writable media, or at the same location as the .apkovl file from the local backup utility lbu .
Enabling Local Cache with current releases
Execute the script
and it will assist in enabling a local cache.
The script creates a symlink named /etc/apk/cache that points to the cache directory.
Cache maintenance
Removing older packages
When newer packages are added to the cache over time, the older versions of the packages default to remain in the cache directory.
The older versions of packages can be removed with the clean command.
apk cache clean
Or to see what is deleted include the verbose switch:
apk -v cache clean
Download missing packages
If you accidentally delete packages from the cache directory, you can make sure they are there with the download command,
apk cache download
Delete and download in one step
You can combine the two steps into one with the sync command — this cleans out old packages and downloads missing packages.
apk cache -v sync
Automatically Cleaning Cache on Reboot
To automatically attempt to validate your cache on reboot, you can add the above command to a /etc/local.d/*.stop file:
Contents of /etc/local.d/cache.stop
Special Caching Configurations
Enabling Local Cache on HDD installs
Note that HDD ‘sys’ installs don’t need an apk cache to maintain their state, it allows to serve packages over the network, though, e.g. to get installed by other local machines.
Manually create a cache dir and then symlink it to /etc/apk/cache:
mkdir -p /var/cache/apk ln -s /var/cache/apk /etc/apk/cache
Local Cache on tmpfs volumes
In some circumstances it might be useful to have the cache reside on tmpfs, for example if you only wish for it to last as long as the system is up.
NOTE: apk is coded to ignore tmpfs caches, and this is correct behaviour in most instances. Using tmpfs as a package cache can consume large amounts of system memory if you install a lot of packages, possibly resulting in a crashed system. You can limit this by restricting the size of your cache to a small number (128M in the example below).
To do it, you need to create an image inside which your cache can live. We do this by creating an image file, formatting it with ext2, and mounting it at /etc/apk/cache.
- apk add e2fsprogs
- dd if=/dev/zero of=/apkcache.img bs=1M count=128
- mkfs.ext2 -F /apkcache.img
- mkdir -p /etc/apk/cache
- mount -t ext2 /apkcache.img /etc/apk/cache
- apk update
As usual, if you want to download currently installed packages into the cache, use apk cache sync.
Manually Enabling Local Cache (required for releases prior to v2.3)
- Create a cache directory on the storage device where you keep the lbu backups (typically, /dev/sda1 .)
mount -o remount,rw /media/sda1
and then don’t forget to run
mount -o remount,ro /media/sda1
when you are done with the following commands
- Create a symlink to this directory from /etc/apk/cache .
ln -s /media/sda1/cache /etc/apk/cache
Run an lbu commit to save the change ( /etc/apk/cache is in /etc and is automatically backed up.)
mount -o remount,ro /media/sda1
now that you are done with saving the changes
Now whenever you run an apk command that pulls a new package from a remote repository, the package is stored on your local media. On startup, Alpine Linux will check the local cache for new packages, and will install them if available.
Advanced APK Usage
Holding a specific package back
In certain cases, you may want to upgrade a system, but keep a specific package at a back level. It is possible to add «sticky» or versioned dependencies. For instance, to hold the asterisk package to the 1.6.2 level or lower:
apk add asterisk=1.6.0.21-r0
apk add ‘asterisk 1.6.1’
will ensure that 1.6.1 is the minimum version used.
You can also use «fuzzy» version matching to pin the version to a major/minor release. For example:
apk add ‘asterisk=
will match any version of asterisk that starts with 1.6 (such as 1.6.0.21-r0 or 1.6.9.31-r9) Alpine source commit message
If you desire deterministic, repeatable package installation (such as with containerized environments) via package pinning, it is important to understand your package repo’s version retention rules. For example, most Alpine package repos contain an «edge» branch, which may drop package versions that are not deemed fit to make it into a stable branch. This means that pinning to a version on the edge branch may stop working after the package version is revoked from the repo. Always pin to a package version that is intended for your current Alpine Linux version.
Troubleshooting
«apk-tools is old»
apk update, apk upgrade or apk add may report the following:
This may happen if you are running Alpine Linux stable version with a certain edge/main, edge/community or testing package(s) also installed. One resolution is to consider upgrading apk-tools . If edge is already tagged in your repositories, then try:
Источник