Docker not port forwarding correctly?

Fadi picture Fadi · Dec 31, 2015 · Viewed 17.1k times · Source

I am trying to run a gitlab docker image, and everything is running fine except that when I navigate to the website, Port 80 results in "Connection refused", but port 8080 successfully reaches Gitlab.

However, it shows that it's forwarding from 8080 to 80 on the container:

CONTAINER ID    IMAGE               COMMAND              CREATED               STATUS               PORTS                                          NAMES
14b2ac3c0de6    gitlab/gitlab-ee    "/assets/wrapper"    About a minute ago    Up About a minute    0.0.0.0:8080->80/tcp, 0.0.0.0:8443->443/tcp    gitlab

Here's how I'm running the container.

sudo docker run --detach \
    --publish 8443:443 --publish 8080:80 --publish 2222:22 \
    --name gitlab \
    --restart always \
    --volume /srv/gitlab/config:/etc/gitlab \
    --volume /srv/gitlab/logs:/var/log/gitlab \
    --volume /srv/gitlab/data:/var/opt/gitlab \
    gitlab/gitlab-ee:latest

Answer

Matt picture Matt · Jan 3, 2016

Use --publish 80:80 if you want to access the service via port 80 on the host. Otherwise there's nothing on the host listening on port 80 and you get connection refused. Same goes for 443.

The format is

 --publish <host port>:<container port>