sauumum
sauumum

Reputation: 1788

'-' character in Docker compose file

The Docker compose file to create a MariaDB container is shown below:

version: '2'
services:
  mariadb:
    container_name: mytest
    image: 'mariadb:X.X.X'
    restart: always
    ports:
    - '3306:3306'
    environment:
    - MYSQL_ROOT_PASSWORD=root

My question is why we are using '-' for 'ports' and 'environment'. Is this only for readability purpose or it has some other importance also?

Upvotes: 0

Views: 165

Answers (2)

Marc Sances
Marc Sances

Reputation: 2614

Because both ports and environment are YAML collections, since you can have multiple port mappings and environment variables.

Check YAML - Collections.

Upvotes: 0

HRK44
HRK44

Reputation: 2762

It is based on YAML, the '-' is to start a list of elements, so you can have multiple ones.

Upvotes: 2

Related Questions