DarcliGht
DarcliGht

Reputation: 1637

docker-compose : Unsupported config option for services service: 'web'

I am going through the Getting Started with Docker Compose page.

In Step 3, I made a docker-compose.yml file as described:

version: '2'
services:
    web:
        build: .
        ports: 
            - "5000:5000"
        volumes: 
            - .:/code
        depends_on:
            - redis
    redis:
        image: redis

But when I run:

$ docker-compose up

I get following error:

Unsupported config option for services service: 'web'

What am I doing wrong? I was not able to figure out what is going on.

Upvotes: 123

Views: 257200

Answers (8)

DaWe
DaWe

Reputation: 1702

There are a couple of things that can cause this problem, try these fixes:

  • The most common reason is a missing version: "3" from the start of your docker-compose.yml.
  • On Ubuntu: try docker compose instead of docker-compose
  • Check the indentation of your docker-compose.yml file to ensure it is correct

Upvotes: 2

Resonance
Resonance

Reputation: 3786

When using Ubuntu I had to be sure to use docker compose (with a space) rather than docker-compose (with a dash). On OSX it didn't seem to matter.

Upvotes: 13

Added version: '3.1' at the top of my docker-compose.yml file and it worked

Upvotes: 5

A. Alae
A. Alae

Reputation: 33

Check the indentation of your docker-compose file.

Try to open the file with Notepad++ (8.4.7 or a newer version). The whole file should show a green strip in the left. If it's orange or the green strip doesn't show for the entire file, it means the file is not valid an therefore not ready to go in your command line.

Hope it helps. It did in my case :)

Upvotes: 0

Brijesh Kalkani
Brijesh Kalkani

Reputation: 851

I would recommend upgrading your docker-compose version, At the moment the safest way to upgrade docker-compose is by deleting it and reinstalling it.

rm /usr/local/bin/docker-compose

Reinstall:

Update the apt package index, and install the latest version of Docker Compose:

 sudo apt-get update

 sudo apt-get install docker-compose-plugin

Alternatively, to install a specific version of Compose CLI plugin:

a. List the versions available in your repo:

apt-cache madison docker-compose-plugin

b. From the list obtained use the version string you can in the second column to specify the version you wish to install. c. Install the selected version:

sudo apt-get install docker-compose-plugin=<VERSION_STRING>

where <VERSION_STRING> is, for example,2.3.3~ubuntu-focal.

And verify that Docker Compose is installed correctly by checking the version.

docker compose version

Upvotes: 2

Muteshi
Muteshi

Reputation: 1318

In my case i had used a wrong indentation. Recheck indentation of your docker-compose file to ensure it is correct

Upvotes: 3

ospider
ospider

Reputation: 10421

Since this is the first result on Googling "docker-compose Unsupported config option for services", I would like to add that the most common reason as of 2020 is missing of version: "3".

Just add version: "3" to the start of your docker-compose.yml.

From the docs:

There are currently three versions of the Compose file format:

  1. Version 1, the legacy format. This is specified by omitting a version key at the root of the YAML.
  2. Version 2.x. This is specified with a version: '2' or version: '2.1', etc., entry at the root of the YAML.
  3. Version 3.x, the latest and recommended version, designed to be cross-compatible between Compose and the Docker Engine’s swarm mode. This is specified with a version: '3' or version: '3.1', etc., entry at the root of the YAML.

Upvotes: 134

larsks
larsks

Reputation: 311606

Support for the version 2 compose file format was introduced in docker-compose version 1.6, released around February of this year.

You're using 1.3.3, from July 2015.

You need to upgrade to a more recent version to use the version 2 format configuration files.

Upvotes: 68

Related Questions