Citrullin
Citrullin

Reputation: 2321

Bridge docker container port to host port

I run a docker container with the following command:

docker run -d --name frontend_service -net host --publish=3001:3000 frontend_service

As I understand it maps the local port 3001 to the container port 3000. I already ssh to the container and checked curl localhost:3000. Works. But outside, on the host, I can't curl localhost:3001.

I checked nmap. The port is open:

nmap -v -sT localhost

Starting Nmap 6.47 ( http://nmap.org ) at 2016-10-19 01:24 UTC
Initiating Connect Scan at 01:24
Scanning localhost (127.0.0.1) [1000 ports]
Discovered open port 25/tcp on 127.0.0.1
Discovered open port 22/tcp on 127.0.0.1
Discovered open port 5051/tcp on 127.0.0.1
Discovered open port 3001/tcp on 127.0.0.1
Completed Connect Scan at 01:24, 0.06s elapsed (1000 total ports)
Nmap scan report for localhost (127.0.0.1)
Host is up (0.0011s latency).
Other addresses for localhost (not scanned): 127.0.0.1
Not shown: 996 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
25/tcp   open  smtp
3001/tcp open  nessus
5051/tcp open  ida-agent

How can i connect the container port with my host port?

Upvotes: 3

Views: 980

Answers (1)

programmerq
programmerq

Reputation: 6534

When you specify --net=host, you are completely turning off Docker's network setup steps. The container won't get its own network namespace, won't get its own interfaces, and the port publishing system will have nothing to route to.

If you want your -p 3001:3000 to work, don't use --net=host.

Upvotes: 5

Related Questions