Publishing Docker Ports Via -P or -p
1. Map The Host Ports To Specific Ports Like TCP or UDP
To try this on your system you can use Apache HTTPD docker image.
#docker run \ -d \ -p 8080:80/tcp \ image
#docker run \ -d \ -p 8080:80/udp image
-d is used to run the docker container server in detached mode.
2. Publishing Any Range Of Ports To Container
#docker run \ -d \ -p 8000-8004:4000-4004 \ image
3. Publish Random Ports
Do not specify any port in the published tag, this will publish some randomly chosen ports to all the exposed ports of the docker container application. Always remember -P is in capital letters for this random allocation.
#docker run \ -d \ -P \ image
How to Map Ports in Docker?
In docker, all the application in the container runs on particular ports when you run a container. If you want to access the particular application with the help of a port number you need to map the port number of the container with the port number of the docker host.