Docker build error: failed to add the host
Asked Answered
S

4

10

I'm facing an unexpected error when running docker build, and I say unexpected because I haven't changed my Dockerfile for a while, and it had worked fine for the last time two weeks ago, but now I'm getting the following error:

failed to create endpoint optimistic_spence on network bridge: failed to add the host (veth9fc3a03) <=> sandbox (veth15abfd6) pair interfaces: operation not supported

In case it is of any help:

  • Docker version is 18.06.0-ce, build 0ffa8257ec
  • I don't see any container with docker ps
  • Systemd returns an active status for the docker process (sudo systemctl status docker)
  • Build command is: docker build -t user/repo:tag .

Dockerfile looks like:

FROM alpine:3.4

LABEL version="current version"
LABEL description="A nice description."
LABEL maintainer="[email protected]"

RUN apk update && apk add \
    gcc \
    g++ \
    make \
    git \
    && git clone https://gitlab.com/user/repo.git \
    && cd repo \
    && make \
    && cp program /bin \
    && rm -r /repo \
    && apk del g++ make git

WORKDIR /tmp

ENTRYPOINT ["program"]

Does anybody understand what is going on? Thank you!

EDIT When combined with the --network option, the error changes a little, but it won't fix the problem. For example, --network=host gives the following:

fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz

ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.4/main: temporary error (try again later)

WARNING: Ignoring APKINDEX.167438ca.tar.gz: No such file or directory

fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz

ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.4/community: temporary error (try again later)

WARNING: Ignoring APKINDEX.a2e6dac0.tar.gz: No such file or directory 2 errors; 11 distinct packages available

The command '/bin/sh -c apk update && apk add gcc g++ make git && git clone https://gitlab.com/user/repo.git && cd repo && make && cp program /bin && rm -r /repo && apk del g++ make git' returned a non-zero code: 2

Selfwill answered 28/8, 2018 at 13:46 Comment(8)
Try creating another network and adding it to that rather than the default one?Tetrahedral
using the --network option does not fix the problem. I will update the question remarking thisSelfwill
Change your shell script so that each line is a RUN instruction in dockerfile. You may pinpoint which layer causes the errorTetrahedral
Error occurs during the first RUN instruction: RUN apk update.Selfwill
Does other instructions pass? Try something like echo or, better yet wget, so you can check if it can connect to internet. It might be a connection issue. Also, use alpine:latest maybe if possible?Tetrahedral
It seems to be a connection error in fact. Running wget results in exactly the same error than aboveSelfwill
Don't know if related, but i am using docker for win in Win10, and i cannot use hostname to connect to containers anymore. I used to be able to before.Tetrahedral
I got the same error in docker build under Ubuntu. In my case the cause was that I was running a customer kernel, which Docker doesn't seem to like. Booting to stock kernel resolved the issue.Elver
F
17

Had the same error and systemctl restart docker nor pruning og images & system did not do it for me, I ended up rebooting my computer which seems o have resolved the issue.

Forland answered 10/7, 2021 at 11:58 Comment(3)
This happens for me regularly because of a Kernel update. So reboot is the way.Concerto
Yeah. Just restarted and it started working.Garonne
Tried docker system prune --all; did not work. Tried systemctl restart docker; did not work. Tried rebooting the computer; worked.Makeshift
S
6

It looks that something wrong happened with any docker network bridge and it doesn't let you to create the same because is "zombie".

Try with following steps:

  1. docker network prune, and if it doesn't work, try with:
  2. docker system prune <-- Careful, this also will purge your named volumes contents, i.e, volumes that are not assigned to a container. So, if you have volumes assigned to a container, you should have to re-build/create containers.
  3. /etc/init.d/docker restart

Show me what happens and let's see, actually I need more info about your problem if it doesn't solve it to you.

Solidary answered 28/8, 2018 at 14:28 Comment(2)
I get the same error after running both docker network prune and docker system prune :(Selfwill
docker system prune shouldn't prune volumes unless you add --volumes to the command.Uprush
M
2

Just to add to the possible causes. For me (and probably @testix) it was because i did a system upgrade (archlinux), so my kernel modules got upgraded, but i was still running the old kernel, so modules could not be loaded. You can try do modprobe a random module:

modprobe vcan
modprobe: FATAL: Module vcan not found in directory /lib/modules/6.2.7-arch1-1

This means that you have to reboot, (or use --network if you can get away with it).

Mongoloid answered 31/3, 2023 at 12:55 Comment(0)
S
1

Two times I have faced this issue and the way to fix it has always been the same. I'm posting in case it can be of any help for somebody:

  • First, make sure that the DNS server is properly set up (eg. setting DNS to 1.1.1.1).
  • Second, restarting the docker daemon.

For those using systemd in Linux, systemctl restart did not the job for me. I had to stop and start docker to make it work. After that, I could login and pull images again.

Selfwill answered 25/11, 2019 at 18:38 Comment(1)
For reference, restart Docker with systemctl with systemctl restart dockerStirpiculture

© 2022 - 2024 — McMap. All rights reserved.