'Version in "./docker-compose.yml" is unsupported. You might be seeing this error because you're using the wrong Compose file version

Here's my docker-compose.yml file:

version: '3.1'

services:
  a:
    image: tutum/hello-world
  b:
    image: tutum/hello-world

secrets:
  id: my_password

If I run $ docker-compose-up I get this:

Version in "./docker-compose.yml" is unsupported. You might be seeing this error because you're using the wrong Compose file version.

My docker-compose version:

$ docker-compose --version
docker-compose version 1.11.0, build 6de1806

What's wrong here? Shouldn't my docker-compose version support v3.1 of the docker-compose.yml specification (according to the release notes, it does) ?



Solution 1:[1]

You are doing everything right and it should work. But there was a bug in docker-compose 1.11.0 which not recognized file format 3.1 as valid. (3.0 works).

There is already a new release of docker-compose (1.11.1) which includes the bugfix:

Bugfixes

Fixed a bug where the 3.1 file format was not being recognized as valid by the Compose parser

So I would recommend to upgrade your docker-compose version if you want to use file format 3.1.

At the moment the safest way to upgrade docker-compose is by deleting it and reinstalling it.

rm /usr/local/bin/docker-compose

Reinstall:

curl -L https://github.com/docker/compose/releases/download/1.11.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version
docker-compose version 1.11.1, build 7c5d5e4

Now there isn't an error anymore on the file format. (I did not test with your .yml).

docker-compose up
Starting compose_a_1
Starting compose_b_1

Solution 2:[2]

I have resolved the issue by upgrading docker-compose.

Follwed below steps to upgrade docker-compose in ubuntu16.04

step1:

$which docker-compose
/usr/bin/docker-compose

step2:

$sudo rm /usr/bin/docker-compose

step3:

curl -L https://github.com/docker/compose/releases/download/1.20.0/docker-compose-`uname -s`-`uname -m` -o /usr/bin/docker-compose

step4:

chmod +x /usr/bin/docker-compose

Solution 3:[3]

If your file version is 3.7 and you get the following error:

ERROR: Version in "./config.yml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.

Here is the solution:

  1. Remove current binary sudo apt-get remove docker-compose OR sudo rm /usr/local/bin/docker-compose

  2. Download the binary sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose. You can find the current latest version here (1.29.1 as of writing).

  3. Allow execution sudo chmod +x /usr/local/bin/docker-compose

  4. Remove old link sudo rm /usr/bin/docker-compose, make new link sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

I hope this resolves the issue.

Solution 4:[4]

To get the latest version of docker-compose :

sudo apt remove docker-compose
curl -L https://github.com/docker/compose/releases/download/1.28.4/docker-compose-`uname -s`-`uname -m` -o /usr/bin/docker-compose
sudo chmod +x /usr/bin/docker-compose

Solution 5:[5]

If using linux/ubuntu, This is maybe obvious but be careful you run as root e.g.

docker-compose -v

Gives

docker-compose version 1.8.0, build unknown

vs

sudo docker-compose -v 

Gives

docker-compose version 1.17.1, build 6d101fb

Also make sure docker-compose and docker-machine are up to date as @lvthillo states

Solution 6:[6]

try uninstall old version and reinstall.

sudo apt remove docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
reboot

should print out

docker-compose --version
docker-compose version 1.22.0, build 1719ceb

Solution 7:[7]

I had done docker-compose --version prior to implementing lvthillo's solution and I was still getting outdated versions showing up. It turned out I needed to flush the hash list my bash shell was holding onto. hash -r ... hope that is useful for someone else

Solution 8:[8]

We cant able to tell you without watching the particular error firstly check it with by running this command

docker build . when you got the error then search it in google in my case it was the permission error when i tried it with sudo it worked.

Hope it will help you

Solution 9:[9]

As @Ivthillo said, you need to upgrade to version 1.11.1.
You should first remove the current version file

sudo rm -f ${which docker-compose}

then install 1.11.1 version

sudo curl -L "https://github.com/docker/compose/releases/download/1.11.1/docker-compose-$(uname -s|sed -e 's/\(.*\)/\L\1/')-$(uname -m)" -o /usr/local/bin/docker-compose

and give execution permission to it

sudo chmod +x /usr/local/bin/docker-compose

Notice: for installing latest version you can use below command

sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s|sed -e 's/\(.*\)/\L\1/')-$(uname -m)" -o /usr/local/bin/docker-compose

Solution 10:[10]

On osx 10.12.6 sierra

Steps for v1.22 or higher

I had a specific issue/incompatibility where I did not want to completely upgrade docker. I am stuck currently on docker 17.06.0-ce-mac18. So I merely wanted to upgrade docker-compose and nothing else.

My steps:

  • Identify location of docker-compose: which docker-compose
  • Identify docker-compose version: docker-compose --version = docker-compose version 1.14.0, build c7bdf9e
  • backup previous docker-compose?: mv /usr/local/bin/docker-compose /usr/local/bin/docker-compose-bak
  • replace with curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
  • if you need to determine the latest version just check https://github.com/docker/compose/releases and replace version above with latest.
  • verify version: docker-compose --version = docker-compose version 1.22.0, build f46880f

Solution 11:[11]

I solved it by making sure my new code aligns with the rest of the code. It appears as it needs to have a certain format and if it's misaligned in regards to the rest of the code it won't see the 'Valid top-level sections for this Compose file are: version, services, networks, volumes, secrets, configs, and extensions starting with "x-".'

Solution 12:[12]

Try with "sudo"

sudo docker-compose up

Solution 13:[13]

The issue was caused by too low version of docker-compose = 1.25.0, which is unfortunately the highest version Ubuntu supports on any of their current releases, including focal (20.04LTS), groovy (20.10) and hirsute.

Upgraded docker-compose the official docker/non-Debian-way:

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ which docker-compose
/usr/local/bin/docker-compose
$ docker-compose -v
docker-compose version 1.27.4, build 40524192

Reference