简体   繁体   中英

Docker container has no internet: network host or ISP problem

I need help finding a way to access the internet in my docker container.

I changed ISP a few days ago and since then when I 'make up' the microservices of my project, no one container has access to the internet.

After many attempts, I tried this:

--net = host (in the docker run)
--network = host (when I build the image)
network_mode = "host" (in the docker-compose)

And finally I get access to the internet from the containers, but now I can't access to the urls of my services.

Any suggestions ...

Well, I contacted my ISP for connection problems with my docker containers, and they explained to me that they do not support them. Answer: Change ISP.

This is just fast fix on RHEL linux (not safest solution) for allowing container to access external resources (outside docker infrastructure) setting up firwalld

firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --zone=public --permanent --add-service=https
firewall-cmd --permanent --zone=trusted --add-interface=docker0
firewall-cmd --permanent --zone=trusted --add-interface=docker_gwbridge
firewall-cmd --reload

For exposing application outside docker host (server running containers) you have to specify "expose ports" in your docker-compose.yml file

services:
  whoami-test:
    image: containous/whoami
    ports:
      # first is docker host listening port
      # second is docker container exposed port
      - 80:8080 
....

Or using command line command:

docker run --rm \
  -p 80:8080 \
  containous/whoami

Above strongly depends on your server/docker/container configuration so please DO NOT copy paste

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM