What are links in Docker Compose?
Experience Level: Senior
Tags: Docker Compose
Answer
Links allow you to define extra aliases by which a service is reachable from another service. They are not required to enable services to communicate - by default, any service can reach any other service at that service’s name. In the following example, db is reachable from web at the hostnames db and database:
version: "3.9"
services:
web:
build: .
links:
- "db:database"
db:
image: postgres
Related Docker Compose job interview questions
What are Docker Compose profiles good for?
Docker Compose SeniorHow can you run a one off command using Docker Compose?
Docker Compose SeniorHow 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 map ports to a specific service container in Docker Compose?
Docker Compose Senior