How do you map ports to a specific service container in Docker Compose?
Experience Level: Senior
Tags: Docker Compose
Answer
Use ports: property of your service.
version: "3.9"
services:
my-service:
image: mssql
ports: 8000:1433
The first port is a host port, the second port is a container port.
Related Docker Compose job interview questions
How can you define what labels will be used for an image built using Docker Compose?
Docker Compose SeniorHow can you override a command that will be executed in a container of a specific service in Docker Compose?
Docker Compose SeniorHow do you comment out lines that you don't want to be processed by Docker Compose?
Docker Compose SeniorHow do tell Docker Compose to use custom .env2 file without passing it in command-line argument?
Docker Compose SeniorHow do you define a default value in Docker Compose interpolation?
Docker Compose Senior