Karuro
Karuro

Reputation: 11

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

Upvotes: 0

Views: 855

Answers (2)

Karuro
Karuro

Reputation: 11

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.

Upvotes: 1

Facty
Facty

Reputation: 547

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

Upvotes: 0

Related Questions