Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker - docker-compose 'version' doesn't have any configuration options

I am newbie in the Docker world, I spent my holiday to learn this docker (however it is much harder than Vagrant). So I use Ubuntu 16.04, I installed successfully the docker and docker-compose.

I read this tutorial: Quickstart: Docker Compose and Rails But this is not working... maybe the tutorial is not fine.

I have this docker-compose.yml:

db:
    image: postgres
web:
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
       - .:/www/html
    ports:
       - "3000:3000"
    depends_on:
       - db

I got this error always:

$ docker-compose run web rails new . --force --database=postgresql --skip-bundle
ERROR: Validation failed in file './docker-compose.yml', reason(s):
Unsupported config option for 'web' service: 'depends_on'

Mmmm, okay, I read a lot of google result, and it seems I am in a troube, because I use Ubuntu. Unfortunately the highest version number of docker in Ubuntu it is only 1.5.2. (I tried download the 1.7.1 with curl, but 1.5.2 installed automatically.)

$ docker version
Client:
 Version:      1.11.1
 API version:  1.23
 Go version:   go1.5.4
 Git commit:   5604cbe
 Built:        Tue Apr 26 23:43:49 2016
 OS/Arch:      linux/amd64

Server:
 Version:      1.11.1
 API version:  1.23
 Go version:   go1.5.4
 Git commit:   5604cbe
 Built:        Tue Apr 26 23:43:49 2016
 OS/Arch:      linux/amd64

Do you have any ideas, how can I run the rails based docker? I cannot install the docker machine, because I use ubuntu and the installation always will be failed.

However my PHP docker-compose.yml is fine, because I can run it :slight_smile: But this rails tutorial is not good.

like image 304
Dabagab Avatar asked May 09 '16 17:05

Dabagab


4 Answers

The reason is you removed the two first lines of the example tutorial your are following, and they do matter.
Because, looking at the docker version you do have you should be on a version of docker-compose higher than 1.6.x.

To identify this, you can run

$ docker-compose -v

In my case that gets me

docker-compose version 1.7.0, build 0d7bf73

If your version there is 1.7.x or higher then the information below definitely apply to you.

This should be working:

version: '2'   ## <- this line matter and you removed it out the tutorial
services:      ## <- this line also
    db:
        image: postgres
    web:
        build: .
        command: bundle exec rails s -p 3000 -b '0.0.0.0'
        volumes:
            - .:/www/html
        ports:
            - "3000:3000"
        depends_on:
            - db

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

Additionally, here is a little docker-composeversion / Composer file matrix:

Compose file format Docker Engine release
3.8 19.03.0+
3.7 18.06.0+
3.6 18.02.0+
3.5 17.12.0+
3.4 17.09.0+
3.3 17.06.0+
3.2 17.04.0+
3.1 1.13.1+
3.0 1.13.0+
2.4 17.12.0+
2.3 17.06.0+
2.2 1.13.0+
2.1 1.12.0+
2.0 1.10.0+
1.0 1.9.1.+

Source: https://docs.docker.com/compose/compose-file/compose-versioning/#compatibility-matrix

  • Version 1 is supported by Compose up to 1.6.x. It will be deprecated in a future Compose release.
  • Version 2 files are supported by Compose 1.6.0+ and require a Docker Engine of version 1.10.0+.
  • An upgrade of version 2 that introduces new parameters only available with Docker Engine version 1.12.0+
  • An upgrade of version 2.1 that introduces new parameters only available with Docker Engine version 1.13.0+. This version also allows to specify default scale numbers inside the service’s configuration.
  • Designed to be cross-compatible between Compose and the Docker Engine’s swarm mode, version 3 removes several options and adds several more.

On docker documentation pages there are also now practical guides on how to upgrade your Compose file:

  • One to upgrade from 1 to 2.x
  • One to upgrade from 2.x to 3.x

Additional useful docker Compose documentation:

like image 156
β.εηοιτ.βε Avatar answered Oct 19 '22 20:10

β.εηοιτ.βε


This shows that the version of your docker-compose is of a lesser version. So, if you are on Ubuntu, you can uninstall docker-compose:

sudo apt-get purge docker-compose

Then, you can re-install the latest version with these command:

curl -L "https://github.com/docker/compose/releases/download/1.10.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Then,

chmod +x /usr/local/bin/docker-compose
like image 43
goodnesskay Avatar answered Oct 19 '22 20:10

goodnesskay


In addition to @b.enoit.be answer:

Ubuntu (and probably Debian) users:

Do not use apt docker-compose package!

If you are using it right now:

apt purge docker-compose

It works just fine with their official instructions:

curl -L "https://github.com/docker/compose/releases/download/1.10.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose;
chmod +x /usr/local/bin/docker-compose;
docker-compose --version; // docker-compose version 1.10.0, build 4bd6f1a

You might want to install their official docker-engine too first, if you also used apt packages for this.

like image 33
zurfyx Avatar answered Oct 19 '22 18:10

zurfyx


I think the answer from b.enoit.be is the right one but just for completeness (and for the sake of anyone using an old version of docker-compose who can't update just yet) it should be possible to make this work by changing depends_on to links:

db:
    image: postgres
web:
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
       - .:/www/html
    ports:
       - "3000:3000"
    links:
       - db

This is because depends_on has only been added in the new version of the docker-compose format.

like image 2
joelnb Avatar answered Oct 19 '22 20:10

joelnb