Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker not port forwarding correctly?

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
like image 828
Fadi Avatar asked Dec 31 '15 15:12

Fadi


People also ask

How does Docker port forwarding work?

We open a host port to give us access to a corresponding open port inside the Docker container. Then all the requests that are made to the host port can be redirected into the Docker container. Port mapping makes the processes inside the container available from the outside.

Does Docker use port 8080?

Docker also finds ports you expose with --expose 8080 (assuming you want to expose port 8080). Docker maps all of these ports to a host port within a given epehmeral port range . You can find the configuration for these ports (usually 32768 to 61000) in /proc/sys/net/ipv4/ip_local_port_range .

How do I know if my Docker port is exposed?

Exposed ports are visible when you list your containers with docker ps . They'll show up in the PORTS column, even though they won't actually be accessible outside the container. This gives you a simple way of checking which ports the software inside a container is listening on.


1 Answers

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>
like image 139
Matt Avatar answered Sep 24 '22 16:09

Matt