I created a docker container with also the command part -p :8080 so a random port from the host will route the requests to the port 8080 on the docker container -->>8080/tcp I had to write -p 8080:8080 so the request to the port 8080 on the host will route this requests to the 8080 port on the docker container.

How can I change this that the port 8080 of the host will connect to the port 8080 of the docker container?


All you have to do is -p and that would connect the container port to the host port which both happen to be the same number. I personally prefer having the IP address there as well, just for self-documenting the code.

| improve this answer | |
  • -p has different effect than -p 8080:8080, and other than -p 8080. First opens port at, second opens, and third opens<random 49152 to 65535 port>, (all three mapped to 8080 port of container indeed). – spacediver Mar 2 '16 at 23:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.