I ran this:
$ docker run -p 8080 --rm my_container
which I guess maps the container port 8080 to some random available port on the host. But how do I find out which port?
The left-hand side of the port number mapping is the Docker host port to map to and the right-hand side is the Docker container port number. When you open the browser and navigate to the Docker host on port 8080, you will see Jenkins up and running.
The Docker client will default to connecting to unix:///var/run/docker.sock on Linux, and tcp://127.0.0.1:2376 on Windows. For example: tcp:// -> TCP connection to 127.0. 0.1 on either port 2376 when TLS encryption is on, or port 2375 when communication is in plain text.
Map TCP port 80 in the container to TCP port 8080 on the Docker host, and map UDP port 80 in the container to UDP port 8080 on the Docker host.
You can use the docker port
command:
docker port my_container
This command output like the following (example with MySQL image):
3306/tcp -> 0.0.0.0:3306
The value before ->
specifies the port on the container side. The value after ->
specifies the chosen port on the host machine.
You can also run the container with a specific port on the host machine (if available):
docker run -p "80:8080" --rm my_container
This would give the following output on docker port
:
8080/tcp -> 0.0.0.0:80
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With