Docker Community Forums

Share and learn in the Docker community.

Docker container not connecting to internet in CentOS 7

I have a CentOS 7.0 host machine, with Docker version 19.03.4, build 9013bf583a installed. I am trying to create a simple docker image

I have a the following Docker file (dockerfile.txt).

FROM alpine:edge
MAINTAINER javaonfly
RUN ping

I then execute the following command

sudo docker build --network=host --file=dockerfile.txt --tag=myrep/image1 --rm=true .

I see the following output

Step 1/3 : FROM alpine:edge
—> 7eacb6761fa1
Step 2/3 : MAINTAINER javaonfly
—> Using cache
—> 77818d634212
Step 3/3 : RUN ping
—> Running in 678b317bbc2c
PING ( 56 data bytes

I observe that the PING is stuck for very long. If I execute the same docker file on AWS EC2 linux machine I see the response to the ping.

On the host machine, I can successfully run the command docker run hello-world. I can also ping to from host machine. But, it seems the alpine:edge container is not able to connect to internet.

I am completely stuck as I do not understand what settings should I check. Thanks.

The default implementation of ping simply doesn’t stop pinging until you cancel it.

Simply try ping -c4

can you try below to verify if it works

I have fixed the issue. I think, because my host is behind a proxy, I had to exclusively mention the proxy server in the build command. Here is the command that tworked for me.

sudo docker build --build-arg http_proxy=http://proxyserver:8080 --build-arg https_proxy=https://proxyserver:8080 --file=inDockerfile.txt --rm=true .

Hellow, I had the same issue.
This link fixed my problem.

. I added (, dns servers to /etc/docker/daemon.json .

After three years of using docker without problems, this issue is affecting me today. The only two new things at the time it showed up are (1) used a debian container for the first time, (2) added my user to the docker group and began using docker without sudo.

Attempted fixes which did not work:

sudo systemctl restart docker

Toggle --iptables dockerd switch between true and false, restarting docker service between toggles.

Adding VIF using sudo brctl addif docker0 .

Forcing rebuild of bridge

sudo systemctl stop docker
sudo pkill docker
sudo iptables -t nat -F
sudo ifconfig docker0 down
sudo brctl delbr docker0
sudo systemctl start docker
I am using docker version 17.12.1-ce, build 7390fc6 on Ubuntu 17.10.