8

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
zondo
  • 19,901
  • 8
  • 44
  • 83
Fadi
  • 1,329
  • 7
  • 22
  • 40
  • Are you using `localhost` or the container's IP to access the service? `http://:80` should always work in your example, and as you're mapping the container port 80 to host port 8080, `http://localhost:8080` should work, too. – helmbert Dec 31 '15 at 16:55
  • It's deployed remotely, and I'm using the machine's ip address. So like I'm typing http://10.96.2.17:8080 in order to reach the site right now; I would like to do just http://10.96.2.17 instead. (I do have also a hostname setup for it through Route 53 [AWS]). – Fadi Dec 31 '15 at 17:23

2 Answers2

12

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>
Matt
  • 68,711
  • 7
  • 155
  • 158
  • If want to send packets to container. which steps are needed for that? – ketan Dec 21 '16 at 13:53
  • @kit The above port setting will work for a specific port. You can also give the container [a real world IP](http://stackoverflow.com/a/42240738/1318694) or access to the hosts interface with `--net host` – Matt May 03 '17 at 22:06
0

My solution looks like this:

docker network create --subnet=172.18.0.0/16 selnet docker run --net selnet --ip 172.18.0.2 -p 0.0.0.0:80:8080 --expose=80 hub

I am able to connect to my container with localhost:Port or 172.18.0.2:Port

Nils Zenker
  • 659
  • 7
  • 11