skip to Main Content

I have recently pulled an official repository from docker consisting of docker-compose templates.

When I try to build and run nginx-golang-mysql/docker-compose.yml with docker-compose up -d I get the following error:

ERROR: The Compose file './docker-compose.yaml' is invalid because:
Unsupported config option for volumes: 'db-data'
Unsupported config option for secrets: 'db-password'
Unsupported config option for services: 'proxy'

This is my docker-compose.yml file (original available on github):

services:
  backend:
    build: backend
    secrets:
      - db-password
    depends_on:
      db:
        condition: service_healthy
  db:
    # We use a mariadb image which supports both amd64 & arm64 architecture
    image: mariadb:10.6.4-focal
    # If you really want to use MySQL, uncomment the following line
    #image: mysql:8.0.27
    command: '--default-authentication-plugin=mysql_native_password'
    restart: always
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "--silent"]
      interval: 3s
      retries: 5
      start_period: 30s
    secrets:
      - db-password
    volumes:
      - db-data:/var/lib/mysql
    environment:
      - MYSQL_DATABASE=example
      - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/db-password
    expose:
      - 3306
  proxy:
    build: proxy
    ports:
      - 80:80
    depends_on: 
      - backend
volumes:
  db-data:
secrets:
  db-password:
    file: db/password.txt

These are my versions of docker and docker-compose:

Docker version 20.10.13, build a224086
docker-compose version 1.25.0, build unknown

Any idea why I’m getting these errors? The other compose-files throw a similar error when I try to run them. I’m using this version of Docker and docker-compose for other projects successfully on a daily basis.

2

Answers


  1. Chosen as BEST ANSWER

    As per Zeitounator's comment:

    The problem was I have installed docker-compose from apt and not from the official repository. The apt only had 1.25 version and I believed it was the latest. In fact the latest is 1.29 at the moment. After installing the latest version as shown in the official docs it now works.

    The pip install --upgrade docker-compose didn't update it for me. I had to remove the version installed with apt and install it again from the official docker repo.


  2. Compose file version 3 requires a version: label; see About versions and upgrading. You need to add this line, usually at the start of the file:

    version: '3.8'
    

    Absent this line, docker-compose interprets the file as a version 1 Compose file. This omits the top-level services: key and puts all services at the top level of the file, but it also does not support volumes: or networks:, and modern Docker networking doesn’t work with a v1 Compose file.

    An argument could be made that the newer Compose Specification makes version: optional. However, removing it makes the file incompatible with existing tooling, as you’ve seen in this question, and I would always include it.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search