Beta 15: Port mapping not working

Expected behavior

Connecting from inside the container to host

Actual behavior

Connection refused


Starting up a container with:

docker run -d -p 2222:22 -p nitai/r2

Inspect shows that ports are open:

"PortBindings": {
                "22/tcp": [
                        "HostIp": "",
                        "HostPort": "2222"
                "27017/tcp": [
                        "HostIp": "",
                        "HostPort": "27017"
Docker for Mac: version: mac-v1.11.2-beta15
OS X: version 10.11.5 (build: 15F34)
logs: /tmp/20160613-105327.tar.gz
failure: No error was detected
[OK]     docker-cli
[OK]     app
[OK]     menubar
[OK]     virtualization
[OK]     system
[OK]     osxfs
[OK]     db
[OK]     slirp
[OK]     moby-console
[OK]     logs
[OK]     vmnetd
[OK]     env
[OK]     moby
[OK]     driver.amd64-linux

Is this currently not supported?

I am having the same issue. Also using beta 15.
Edit: I found my issue was caused by the application inside docker binding to I changed it to bind to and everything started working. This was not specific to the docker for mac beta.


Oh ? I thought it needs to bind to as outlined in my settings above. I’ll try right now too.

No. Its still mapped to on the host. It was the app I am running inside the container that was binding to localhost.

Yeah, somehow it doesn’t work for me. I’m running a node.js app inside the container and I want it to connect to the MongoDB running on the host. Whatever, I try it fails to connect.


Change connection from node.js to mongo to be - fails
Change connection from node.js to mongo to be - fails

Run the container:

docker run -d -p 2222:22 -p nitai/r2
docker run -d -p 2222:22 -p 27017:27017 nitai/r2

Can you spot what I’m missing here?

Thank you.

I see. You are connecting from the container to the host (I misread your initial post). In order to do that, you would need the ip of the host from within the container. There isn’t really a good way of doing this yet. You can see the discussion on here:

and now here:

Yes, thanks. However, I’m creating a “customer facing” script where I’m trying to shield of all those things. I think I just have to resort to linking and only that is really supported, i.e. running MongoDB in another container and not on the localhost.

If you have DNS in place, you can simply use your host DNS name (perhaps passing it to the container as an env variable).

  • Edit: make sure that your container is using a DNS that can resolve your host’s hostname!
1 Like

Yes, that would be an alternative. I think for now I simply use links.

Thanks, this was super helpful, setting the Docker configuration in MAC,
Setting the ip address will be the IP address on which the docker port will map to.

  "debug" : true,
  "ip" : "",

Then as per the advise I set my application to run on host -