A reliable fix to Docker not keeping it's IPV4 address on Arch

A summary of the problem and fix I experienced with docker0 on arch

vados

3 minute read

tl;dr - Scroll to the bottom for the fix, if you’re having the problem, thanks to Garett L Ward for submitting the fix to me over email!

This is a bit of a repost (since I’ve aleady gone into the fix in an update to the previous post), but I wanted to say it again for anyone who might find this on the internet. If you’re struggling with an issue similar to the one described in one of my previous posts regarding docker0 losing it’s IPV4 address all the time, here’s a quick recap of how I got it fixed, big thanks to Garrett for figuring this out and emailing me:

Problem

If you find that you’re running into weird problems with containers accessing the outside world on arch, for example if you use an alpine container, but can’t successfully perform any apk add commands with an error like:

Step 2/4 : RUN apk --update add git make
 ---> Running in 0c8337ad3f53
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.5/main: temporary error (try again later)
WARNING: Ignoring APKINDEX.c51f8f92.tar.gz: No such file or directory
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/community/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.5/community: temporary error (try again later)
WARNING: Ignoring APKINDEX.d09172fd.tar.gz: No such file or directory
ERROR: unsatisfiable constraints:
  git (missing):
    required by: world[git]
  make (missing):
    required by: world[make]
The command '/bin/sh -c apk --update add git make' returned a non-zero code: 2
make: *** [Makefile:30: docker-build-image] Error 2

At first I thought the issue was that the CDN was actually down, but it actually isn’t – you can test this by using cURL to hit the address from your local computer.

Fix

1. Check if SystemD is trying to manage your docker0 link by running networkctl. Here’s the output I saw:

$ networkctl
IDX LINK             TYPE               OPERATIONAL SETUP
  1 lo               loopback           routable    configured
  2 enp3s0           ether              routable    configured
  3 docker0          ether              no-carrier  configuring


3 links listed.

2. Ensure that systemd will NOT manage the endpoint, since docker is by adding this file to one of the configuration locations for SystemD NetworkD: /etc/systemd/network

# Ensure that the 'docker0' interface is unmanaged

[Match]
Name=docker0

[Link]
Unmanaged=yes

You can read more about the configuration options in this file in the man pages for systemd-networkd

3. Reload the configuration with systemctl restart systemd-networkd

4. Re-check the output of networkctl, after doing this I see:

$ networkctl
IDX LINK             TYPE               OPERATIONAL SETUP
  1 lo               loopback           routable    unmanaged
  2 enp3s0           ether              routable    unmanaged
  3 docker0          ether              no-carrier  unmanaged

3 links listed.

I was just a tad worried because lo and enp3s0 (my wired connection) also said that they were unmanaged (which I certainly didn’t configure), but as the internet is still working, I doubt that issue will survive a restart.

5. Restart the docker systemd service with systemctl restart docker and attempt to build the container again

Did you find this read beneficial? Send me questions/comments/clarifciations.
Want my expertise on your team/project? Send me interesting opportunities!