> 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 900f5e2ff097677bd6af8825cd0f0f6961b462714528d75245e73841d0f4f30c docker: Error response from daemon: driver failed programming external connectivity on endpoint webserver (4fa9e84616ebb7c7aa86a345a4caa01910d8fdcb00b71d0bd8daf6b9443a0a7a): Error starting userland proxy: Bind for 0.0.0.0:80: 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 b2605b247f405a74761e042ed089e966995bfcce6b8268696410314ac6984965
I was then able to successful query the service on port 3060 by using curl or using my browser at http://localhost:3060/.