How to use binaries installed with `apk` `--force-broken-world` flag
Asked Answered
A

1

8

I've been reading the man pages for apk add, but I don't fully understand how to use the --force-broken-world flag.

I was trying to install Python 2.7.6 into an Alpine image, but I got the following error.

$ docker run --rm -it alpine:latest apk add --no-cache python=2.7.6
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
  python2-2.7.14-r2:
    breaks: world[python=2.7.6]

However, I can force install it, but I'm not certain what, if anything, it is doing.

$ docker run --rm -it alpine:latest apk add --force-broken-world --no-cache python=2.7.6
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
OK: 4 MiB in 11 packages

From the command line, everything looks good. However, when you do this inside the container, python doesn't seem to be installed.

$ docker run --rm -it alpine:latest /bin/ash
# apk add --force-broken-world --no-cache python=2.7.6
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
OK: 4 MiB in 11 packages
# python --version
/bin/ash: python: not found
# find / -name ash
/bin/ash
# find / -name python
#

So the question is, what exactly does the --force-broken-world flag do, and what other steps will I need to take to repair my broken world?

Allix answered 5/2, 2018 at 17:52 Comment(0)
B
0

The world file is what's keeping all packages you want to add. So if you add a new package via apk add it will be added to the world file:

World file:

# cat /etc/apk/world
alpine-baselayout
alpine-keys
apk-tools
busybox
libc-utils

Now add a package and see the difference in world file:

/ # apk add binutils
(1/5) Installing libgcc (13.2.1_git20231014-r0)
(2/5) Installing jansson (2.14-r4)
(3/5) Installing libstdc++ (13.2.1_git20231014-r0)
(4/5) Installing zstd-libs (1.5.5-r8)
(5/5) Installing binutils (2.41-r0)
Executing busybox-1.36.1-r15.trigger
OK: 24 MiB in 20 packages
/ # cat /etc/apk/world
alpine-baselayout
alpine-keys
apk-tools
binutils
busybox
libc-utils

If you are installing a package that's not available like python in this case, it won't be added to the world file:

/ # apk add python=2.7.6
ERROR: unable to select packages:
  python (no such package):
    required by: world[python=2.7.6]
/ # cat /etc/apk/world
alpine-baselayout
alpine-keys
apk-tools
binutils
busybox
libc-utils

However, if you force-broken-world it will be added regardless if it's available or not:

/ # apk add --force-broken-world python=2.7.6
OK: 24 MiB in 20 packages
/ # cat /etc/apk/world
alpine-baselayout
alpine-keys
apk-tools
binutils
busybox
libc-utils
python=2.7.6

Now this doesn't change the availability of the package, meaning you still won't get python from this, just when you run apk add the next time without any other arguments it will again try to install it, but still find it's not there:

/ # apk add
ERROR: unable to select packages:
  python (no such package):
    required by: world[python=2.7.6]

There various use cases, for example if you build a list of packages you need to install that might not be available on the box your building on because you can't connect to the repo but will be available later.

If you want to "fix" your broken world, you can remove the package from the world file using any text editor of choice.

Further read: https://docs.alpinelinux.org/user-handbook/0.1a/Working/apk.html#_world

Benghazi answered 28/12, 2023 at 8:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.