Docker port mapping syntax¶
Docker port mapping syntax refers to the configuration format used to expose container ports to the host machine or other external services. This mapping creates a connection between a port on the host (interface) and a specific port inside the container, allowing external traffic to reach the application running within the container^[600-developer__docker__docker-compose__docker-compouse-02.md].
Syntax Structure¶
The syntax follows the format "HOST_PORT:CONTAINER_PORT".^[600-developer__docker__docker-compose__docker-compouse-02.md]
- Host Port: The number on the left of the colon represents the port opened on the host machine or the external interface.
- Container Port: The number on the right of the colon represents the port listening inside the container.
Implementation¶
In Docker Compose configurations, this mapping is defined under the ports section of a service definition^[600-developer__docker__docker-compose__docker-compouse-02.md]. The values are typically formatted as strings (often enclosed in quotes) to ensure proper parsing by the YAML interpreter^[600-developer__docker__docker-compose__docker-compouse-02.md].
For example, to map the host's port 33060 to the default MySQL port 3306 inside the container, the configuration would look like "33060:3306"^[600-developer__docker__docker-compose__docker-compouse-02.md].
Related Concepts¶
- Docker Compose
- [[Reverse Proxy]] (often used in conjunction with port mapping)
- [[Service Discovery]]
Sources¶
^[600-developer__docker__docker-compose__docker-compouse-02.md]