I don't know if there is a difference between ports with or without quotes in a docker-compose.yml
file, can't find any good documentation.
ports:
- "80:80"
- "443:443"
ports:
- 80:80
- 443:443
I see no difference when I run it
Ports is defined as: Either specify both ports (HOST:CONTAINER), or just the container port (a random host port will be chosen). Ports mentioned in docker-compose. yml will be shared among different services started by the docker-compose. Ports will be exposed to the host machine to a random port or a given port.
Docker Compose exposes all specified container ports, making them reachable internally and externally from the local machine. Once again, in the PORTS column, we can find all the exposed ports. The value to the left of the arrow shows the host address where we can reach the container externally.
Publishing a port makes it accessible from outside the container. It lets you take a port you've discovered by an EXPOSE instruction, then bind a host port to it. This command binds port 8080 on your Docker host to 80 inside your new container.
Note from Docker Compose file version 3 reference:
When mapping ports in the HOST:CONTAINER format, you may experience erroneous results when using a container port lower than 60, because YAML parses numbers in the format xx:yy as a base-60 value. For this reason, we recommend always explicitly specifying your port mappings as strings.
https://docs.docker.com/compose/compose-file/compose-file-v3/#ports
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