Docker Community Forums

Share and learn in the Docker community.

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: