To map the application or the host port number to the docker container port number, you can use the
docker run command followed by the
-p flag (port number flag) and then the docker port number followed by a
: (colon) and then the application port number and then the name of the docker image to use.
# Map application or host port number # to docker container port number docker run -p <DOCKER_PORT_NUMBER>:<APPLICATION_PORT_NUMBER> docker/getting-started # Example: # -------- # docker run -p 3000:80 docker/getting-started
For example, let's say we want to run a docker container on port
3000 in which the original application port number is running on port number
To do that we can use the
docker run command like this,
# Map application or host port number # to docker container port number docker run -p 3000:80 docker/getting-started
- After running the above command the docker container which is using the
docker/getting-startedimage can be accessible at
localhost:3000even though the original application port number is
And like that, we have successfully mapped the docker container port number to the application or the host port number 🎉.
If you want to try out the docker commands online, see the Play with docker lab website to test out the commands.
That's all 😃!