31

I'm trying to understand the Dockerfile https://hub.docker.com/r/rdsubhas/tor-privoxy-alpine/~/dockerfile/, which contains a RUN executive with

apk --update add privoxy tor@testing runit@testing

I wanted to check my understanding of how the apk command is being used, so I tried opening a terminal in the Alpine environment as follows:

docker run -it --rm alpine:latest /bin/ash

after which I simply ran apk to see its usage:

/ # apk
apk-tools 2.6.8, compiled for x86_64.

usage: apk COMMAND [-h|--help] [-p|--root DIR] [-X|--repository REPO]
           [-q|--quiet] [-v|--verbose] [-i|--interactive] [-V|--version]
           [-f|--force] [-U|--update-cache] [--progress] [--progress-fd FD]
           [--no-progress] [--purge] [--allow-untrusted] [--wait TIME]
           [--keys-dir KEYSDIR] [--repositories-file REPOFILE] [--no-network]
           [--no-cache] [--arch ARCH] [--print-arch] [ARGS]...

The following commands are available:
  add       Add PACKAGEs to 'world' and install (or upgrade) them, while
            ensuring that all dependencies are met
  del       Remove PACKAGEs from 'world' and uninstall them
  fix       Repair package or upgrade it without modifying main dependencies
  update    Update repository indexes from all remote repositories
  info      Give detailed information about PACKAGEs or repositores
  search    Search package by PATTERNs or by indexed dependencies
  upgrade   Upgrade currently installed packages to match repositories
  cache     Download missing PACKAGEs to cache and/or delete unneeded files
            from cache
  version   Compare package versions (in installed database vs. available) or
            do tests on literal version strings
  index     Create repository index file from FILEs
  fetch     Download PACKAGEs from global repositories to a local directory
  audit     Audit the directories for changes
  verify    Verify package integrity and signature
  dot       Generate graphviz graphs
  policy    Show repository policy for packages
  stats     Show statistics about repositories and installations

Global options:
  -h, --help              Show generic help or applet specific help
  -p, --root DIR          Install packages to DIR
  -X, --repository REPO   Use packages from REPO
  -q, --quiet             Print less information
  -v, --verbose           Print more information (can be doubled)
  -i, --interactive       Ask confirmation for certain operations
  -V, --version           Print program version and exit
  -f, --force             Do what was asked even if it looks dangerous
  -U, --update-cache      Update the repository cache
  --progress              Show a progress bar
  --progress-fd FD        Write progress to fd
  --no-progress           Disable progress bar even for TTYs
  --purge                 Delete also modified configuration files (pkg
                          removal) and uninstalled packages from cache (cache
                          clean)
  --allow-untrusted       Install packages with untrusted signature or no
                          signature
  --wait TIME             Wait for TIME seconds to get an exclusive repository
                          lock before failing
  --keys-dir KEYSDIR      Override directory of trusted keys
  --repositories-file REPOFILE Override repositories file
  --no-network            Do not use network (cache is still used)
  --no-cache              Read uncached index from network
  --arch ARCH             Use architecture with --root
  --print-arch            Print default arch and exit

This apk has coffee making abilities.

The thing is, I don't see the --update option in this documentation (only --update-cache).

What I suspect is that apk --update add [package] is simply shorthand for apk update followed by apk add [package]. Can anyone confirm this?

Kara
  • 6,115
  • 16
  • 50
  • 57
Kurt Peek
  • 52,165
  • 91
  • 301
  • 526

2 Answers2

37

See https://github.com/gliderlabs/docker-alpine/pull/503

apk --update flag is really --update-cache.

Apk uses getopt_long (3), https://github.com/alpinelinux/apk-tools/blob/v2.10.3/src/apk.c#L574

So, --update flag is only abbreviated from --update-cache by getopt_long.

Long option names may be abbreviated if the abbreviation is unique or is an exact match for some defined option.

Patryk
  • 22,602
  • 44
  • 128
  • 244
mtgto
  • 511
  • 1
  • 5
  • 5
17

In short:

To get the latest list of available packages, use the update command.

it is similar to the Debian apt-get update that you do before apt-get install my_package.

from https://wiki.alpinelinux.org/wiki/Alpine_Linux_package_management#Update_the_Package_list:

extract

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/.

apk update

Tip: If using remote repositories, it is a good idea to do an update just before doing an add or upgrade command. That way you know you are using the latest software available.

valiano
  • 16,433
  • 7
  • 64
  • 79
user2915097
  • 30,758
  • 6
  • 57
  • 59
  • 25
    I see. Is `apk --update add [package]` simply shorthand for doing first `apk update` followed by `apk add [package]`? – Kurt Peek Apr 28 '17 at 14:01
  • 15
    exactly, just that – user2915097 Apr 28 '17 at 14:03
  • Do you have a source for that? I don't think that's true. See the answer below: "`--update` flag is only abbreviated from `--update-cache` by getopt_long." It might be true that this is *also* the same as `apk update` followed by `apk add`, but initially (and the reason why there is no `--update` in the man page) it's the same as `--update-cache`. – finefoot Feb 21 '20 at 16:47
  • 2
    > 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. https://wiki.alpinelinux.org/wiki/Alpine_Linux_package_management#Update_the_Package_list – dtk Sep 16 '20 at 10:41