skip to Main Content

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


  1. Chosen as BEST ANSWER

    I had to rewrite the build section in the docker-compose.yaml to the following in order to fix the problem

        build:
          context: .
          network: host
    

  2. 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:

    # docker run --dns 8.8.8.8 busybox:1.28.0 nslookup google.com
    
    Server:    8.8.8.8
    Address 1: 8.8.8.8 dns.google
    
    Name:      google.com
    Address 1: 2a00:1450:4016:807::200e muc11s04-in-x0e.1e100.net
    Address 2: 216.58.207.174 muc11s04-in-f14.1e100.net
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search