docker expose ports only on host

sorry for my stupid question. I'm using docker and i try to expose port to localhost. I'm using the following command line:

docker run -d -p 127.0.0.1:8080:8081 --name nexus sonatype/nexus

And I'm executing the following command:

wget nexus:8080
--2015-03-26 19:31:58--  http://nexus:8080/
Résolution de nexus (nexus)... 127.0.53.53
Connexion vers nexus (nexus)|127.0.53.53|:8080...échec: Connexion refusée.

I have issue with ping command however why, I can't find nexus server.

I have check and all port are open on (iptables).

Thanks

Upvotes: 3

Views: 1032

Answers (2)

Ofir Petrushka
Ofir Petrushka

Reputation: 51

It's a problem accessing docker like that. You can try this for testing the server:

docker exec -it nexus wget http://nexus:8080/

That would do a local wget inside the docker image.

That docker is accessible from outside your node just as well as it is from inside. It's just that there is no routing from your generic network interface to the docker one.

Upvotes: 0

Adrian Mouat
Adrian Mouat

Reputation: 46480

Where are you running the wget from? You've only bound to the localhost interface on the host, so you will only be able to access the container from the host itself. Does it work if you use 0.0.0.0:8080:8081 in the docker run command? IIRC 0.0.0.0 is the default, so just 8080:8081 should also work.

If you don't want to make the port accessible to anyone outside the local network, use your local IP address, which you can find by running ifconfig. For example, my IP on the local network is 192.168.1.103, so I would do:

docker run -d -p 192.168.1.103:8080:8081 --name nexus sonatype/nexus

Upvotes: 2

Related Questions