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 8.8.8.8

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 8.8.8.8
—> Running in 678b317bbc2c
PING 8.8.8.8 (8.8.8.8): 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 www.google.com 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 8.8.8.8.

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 --tag=692572502211.dkr.ecr.eu-west-1.amazonaws.com/myservice:01.00.04.15 --rm=true .

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


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

same thing happening to me. the strange is that some images do connect to the internet, like node. but not python, debian, ubuntu