garethr / garethr-docker

Puppet module for managing docker
Apache License 2.0
397 stars 532 forks source link

docker_compose fail to run when specifying multiple files #492

Open mickaelperrin opened 8 years ago

mickaelperrin commented 8 years ago

Hi,

I intend to deploy docker containers using the docker_compose puppet command, it works well when I use only one docker-compose.yml file.

However, as soon as I override the main docker-compose configuration file with an additional one, the puppet execution fails, with the following error:

Debug: Executing: '/usr/local/bin/docker-compose -f /home/zu/docker/docker-compose.yml -f /home/zu/src/docker-compose.staging.yml up -d'
Error: Execution of '/usr/local/bin/docker-compose -f /home/zu/docker/docker-compose.yml -f /home/zu/src/docker-compose.staging.yml up -d' returned 1: .IOError: [Errno 2] No such file or directory: u'./ /home/zu/src/docker-compose.staging.yml'
Error: /Stage[main]/Docker_compose::Create_containers/Docker_compose::Container[zu]/Docker_compose[/home/zu/docker/docker-compose.yml]/ensure: change from absent to present failed: Execution of '/usr/local/bin/docker-compose -f /home/zu/docke```r/docker-compose.yml -f /home/zu/src/docker-compose.staging.yml up -d' returned 1: .IOError: [Errno 2] No such file or directory: u'./ /home/zu/src/docker-compose.staging.yml'

I firstly think about a typo error but when manually running the docker-compose command directly on the server, it works.

Here is the simple docker_compose configuration I use:

docker_compose { "/home/zu/docker/docker-compose.yml":
    ensure     => 'present',
    options    => "-f /home/zu/src/docker-compose.staging.yml"
  }

Any ideas, on how to resolve this ?

Some informations about my system:

garethr commented 8 years ago

Hi @mickaelperrin

If you would like to run the .staging compose file simply provide that as the resource name like so:

docker_compose { "/home/zu/src/docker-compose.staging.yml":
  ensure     => 'present',
}

You should be able to have multiple docker_compose resources all pointing at different compose files.

You can see from the output of the Puppet run you are getting two -f arguments to compose which I'd expect to compose.

Also I note that the error says "No such file or directory: u'./ /home/zu/src/docker-compose.staging.yml'" which suggests the compose file in question might not be present.

Let me know if that doesn't resolve your issue.

mickaelperrin commented 8 years ago

Sorry, but indeed that doesn't resolve my issue.

This is a common pattern and good practise with docker-compose to call multiple docker-compose files at the same time, this is call "extendind services" in the docker documentation.

The generated docker-compose is so expected with two -f parameters.

The file /home/zu/src/docker-compose.staging.yml exists, and I previously said, if I manually run the command outputed in the debug log it works /usr/local/bin/docker-compose -f /home/zu/docker/docker-compose.yml -f /home/zu/src/docker-compose.staging.yml up -d

What I don't understand is why I get this ./in the error message, as it doesn't appear in the executed command ?

garethr commented 8 years ago

Ah, interesting. I wasn't familiar with extending services via multiple files like that. When I get a moment I'll take a closer look at supporting this. Thanks for the extra details.

mickaelperrin commented 8 years ago

Just got the same issue using a simple bash function, it looks like this issue is related to https://github.com/docker/compose/issues/3305.

To resolve my issue on my bash script, I simply remove the empty space between the filename and the -f parameter (-fPathToDockerComposeFile.yml). Didn't try it in Puppet, but should do the trick.

I will update this thread, when I will revert back my puppet script from a simple exec to a docker_compose class.

EDIT: To be precise, that didn't work with multiple compose files. Instead of calling variables that holds docker-compose arguments directly as arguments of docker-compose, I needed to create a full command string and then evaluate it.

    CMD="docker-compose $ARGS $@"
    eval $CMD

works, but not:

docker-compose  "$ARGS" "$@"
jontybale commented 8 years ago

Removing the space between the -f and the FILE also resolves the issue - apparently -f FILE and -fFILE are the same. Most likely an issue with http://docopt.org/ as the issue at https://github.com/docker/compose/issues/3305 states.

docker_compose { "/home/zu/docker/docker-compose.yml":
    ensure     => 'present',
    options    => "-f/home/zu/src/docker-compose.staging.yml"
}

Should work - or at least has for me! :)