Cannot access published port

I try do run a basic docker-compose script on centos7. Unfortunately it doesn’t work. Is it really necessary to connect the started nginx container to the default bridge network?

Docker version 19.03.12, build 48a66213fe
docker-compose version 1.26.2, build eefe0d31
/etc/centos-release CentOS Linux release 7.6.1810 (Core)

docker-compose.yml

services:
    nginx:
        image: nginx:latest
        ports:
          - 8080:80

docker-compose up

docker ps
592b63142f79 … nginx:latest 0.0.0.0:8080->80/tcp

wget localhost:8080 --> error

docker network connect bridge 592b63142f79

wget localhost:8080 --> success

When i run nginx with docker itself docker run -p 8080:80 nginx:latest it works.

Cross post at stackoverflow:

1 Like

Facing the similar issue, have you got any workaround for this?

It is probably a firewall issue. Try to disable firewalld for just a minute. If that works, enable it again and try to fix the configuration. I rmemember that when I was on Centos, I had to configure firewalld. Without that my containers could not communicate with each other. But I don’t remember the exact configuration.

An other example for Ubuntu Docker Compose network: cannot use default docker gateway to connect to host machine from container, unless a custom network is manually specified - #5 by swissknight