How do you define a service in the docker-compose file?
Experience Level: Junior
Tags: Docker Compose
Answer
- Create a docker-compose.yml file
- Add version: section
- Add services: section
- Under services section, add a service name
- Under a service name, add build: property that defines a Docker build context (a folder in which the Docker file will be searched for)
version: "3.4"
services:
my-service:
build: .
Related Docker Compose job interview questions
How do you run services from a Docker Compose file in a detached mode?
Docker Compose JuniorHow do you re-build a service my-service that is defined in a Docker Compose file without running the service?
Docker Compose JuniorHow do you install Docker Compose?
Docker Compose JuniorWhat are the key sections of the Docker Compose definition file?
Docker Compose JuniorHow do you run a service with name my-service that is defined in Docker Compose file?
Docker Compose Junior