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: .

Comments

No Comments Yet.
Be the first to tell us what you think.
Docker Compose
Docker Compose

Are you learning Docker Compose ? Try our test we designed to help you progress faster.

Test yourself