docker run docs confusing – which port?

I was reviewing the docker docs today in an attempt to get things working on OSX and ran into a conflict when starting a new container running nginx. The docs say to run the following command:

> docker run -d -p 80:80 --name webserver nginx

That seems pretty straight forward, so I ran the command:

> docker run -d -p 80:80 --name webserver nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
94ed0c431eb5: Pull complete
9406c100a1c3: Pull complete
aa74daafd50c: Pull complete
Digest: sha256:788fa27763db6d69ad3444e8ba72f947df9e7e163bad7c1f5614f8fd27a311c3
Status: Downloaded newer image for nginx:latest
docker: Error response from daemon: driver failed programming external connectivity on endpoint webserver (4fa9e84616ebb7c7aa86a345a4caa01910d8fdcb00b71d0bd8daf6b9443a0a7a): Error starting userland proxy: Bind for unexpected error (Failure EADDRINUSE).

After getting this error, I see that I have something listening on port 80 already, that’s no problem. The logical thing to do would be to refer to the docs real quick to figure out which side of the colon mapped to the port on the container and which side mapped to the port on my OSX host. I could not find an explanation for this in the docker docs. I did a bit of searching around as well, with no luck. I don’t see this documented.

The next logical step, or more likely the first, was to just try them both and see which one worked. The left side is the docker host and the right side is the container, ie:

> docker run  -d -p 3060:80 --name webserver3060 nginx

I was then able to successful query the service on port 3060 by using curl or using my browser at http://localhost:3060/.




Leave a Reply

Your email address will not be published. Required fields are marked *