I am running a docker container on CentOS Linux release 8.2.2004. The CentOs Server itself has a stable internet connection. Ultimately I am trying to start a docker container with the following docker-compose.yaml
version: '3'
services:
postgres:
restart: always
image: postgres:12.1
environment:
POSTGRES_PASSWORD: myusername
POSTGRES_USER: mypass
networks:
- myname
volumes:
- /home/user/data/myname:/var/lib/postgresql/data
ports:
- 5432:5432
web:
restart: always
build: .
environment:
JPDA_ADDRESS: 8001
JPDA_TRANSPORT: dt_socket
networks:
- myname
depends_on:
- postgres
ports:
- 80:8080
- 8001:8001
volumes:
- /home/user/data/images:/data/images
networks:
myname:
driver: bridge
But upon docker-compose build
maven repositories cannot be reached (due to a missing internet connection from with in the docker). Adding dns rules to the yaml doesn’t change anything, neither does setting network_mode: "host"
When I try and execute
docker run --dns 8.8.8.8 busybox nslookup google.com
;; connection timed out; no servers could be reached
Upon trying a normal ping, the connection fails too
docker run -it busybox ping -c 1 8.8.8.8
1 packets transmitted, 0 packets received, 100% packet loss
However
docker run --rm -it busybox ping 172.17.0.1
seems to work just fine.
docker run --net=host -it busybox ping -c 1 8.8.8.8
Works too
how can I get docker to connect to the internet?
2
Answers
I had to rewrite the build section in the docker-compose.yaml to the following in order to fix the problem
Looks like it is a known issue of busybox. Check this thread here: nslookup can not get service ip on latest busybox
On short, you must use busybox versions before 1.28.4.
I just ran the following command on a CentOS 7 with Docker 19 and it worked fine: