A lot of times, I see ports described twice with a colon like in this Docker Compose file from the Docker Networking in Compose page:
version: "3"
services:
web:
build: .
ports:
- "8000:8000"
db:
image: postgres
networks:
default:
# Use a custom driver
driver: custom-driver-1
I've often wondered why the "8000:8000"
and not simply "8000"
Then I saw this example, which has the two ports different:
version: "3"
services:
web:
build: .
ports:
- "8000:8000"
db:
image: postgres
ports:
- "8001:5432"
Can someone explain what this port representation means?
Founded in 1850 at the Atlantic (northern) terminus of the original Panama Railroad (now the Panama Canal Railway), the settlement was first called Aspinwall, named for one of the builders of the railway. Colón is the Spanish form of Columbus; the name of the neighbouring port of Cristóbal is Spanish for Christopher.
yes, it is possible as long as containers are using different IP address. you can check the IP address of the containers by using below command.
The first port is host's port and the second is the remote port (i.e: in the container). That expression bounds the remote port to the local port.
In the example you map container's 8080 port to host's 8080 port, but it's perfectly normal to use different ports (e.g: 48080:8080)
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