herby
By:
herby

Is is the bug that docker appliance does not pass COMPOSE_FILE into docker-compose?

October 24, 2017 136 views
Docker Applications Ubuntu 16.04

root@towergame:~/ops-meta/filmtower/COMPOSE# COMPOSEFILE=nginx.yaml docker-compose --verbose up -d
compose.config.config.find: Using configuration files: ./docker-compose.yaml
docker.auth.find
configfile: Trying paths: ['/root/.docker/config.json', '/root/.dockercfg']
docker.auth.find
configfile: No config file found
compose.cli.command.get
client: docker-compose version 1.13.0, build 1719ceb
docker-py version: 2.2.1
CPython version: 2.7.13
OpenSSL version: OpenSSL 1.0.1t 3 May 2016
compose.cli.command.getclient: Docker baseurl: http+docker://localunixsocket
compose.cli.command.getclient: Docker version: KernelVersion=4.4.0-97-generic, Arch=amd64, BuildTime=2017-05-04T22:10:54.638119411+00:00, ApiVersion=1.29, Version=17.05.0-ce, MinAPIVersion=1.12, GitCommit=89658be, Os=linux, GoVersion=go1.7.5
compose.cli.verbose
proxy.proxy_callable: docker info <- ()
...snip...
root@towergame:~/ops-meta/filmtower/COMPOSE#

As you see, COMPOSE_FILE is not taken into account. As you run docker-compose via docker using a script:

root@towergame:~/ops-meta/filmtower/COMPOSE# cat /usr/local/bin/docker-compose #!/bin/sh

Run docker-compose in a container

This script will attempt to mirror the host paths by using volumes for the

following paths:

* $(pwd)

* $(dirname $COMPOSE_FILE) if it's set

* $HOME if it's set

You can add additional volumes (or any docker run options) using

the $COMPOSE_OPTIONS environment variable.

set -e

VERSION="1.13.0"
IMAGE="docker/compose:$VERSION"

Setup options for connecting to docker host

if [ -z "$DOCKERHOST" ]; then
DOCKER
HOST="/var/run/docker.sock"
fi
if [ -S "$DOCKERHOST" ]; then
DOCKER
ADDR="-v $DOCKERHOST:$DOCKERHOST -e DOCKERHOST"
else
DOCKER
ADDR="-e DOCKERHOST -e DOCKERTLSVERIFY -e DOCKERCERT_PATH"
fi

Setup volume mounts for compose config and context

if [ "$(pwd)" != '/' ]; then
VOLUMES="-v $(pwd):$(pwd)"
fi
if [ -n "$COMPOSEFILE" ]; then
compose
dir=$(realpath $(dirname $COMPOSE_FILE))
fi

TODO: also check --file argument

if [ -n "$composedir" ]; then
VOLUMES="$VOLUMES -v $compose
dir:$compose_dir"
fi
if [ -n "$HOME" ]; then
VOLUMES="$VOLUMES -v $HOME:$HOME -v $HOME:/root" # mount $HOME in /root to share docker.config
fi

Only allocate tty if we detect one

if [ -t 1 ]; then
DOCKERRUNOPTIONS="-t"
fi
if [ -t 0 ]; then
DOCKERRUNOPTIONS="$DOCKERRUNOPTIONS -i"
fi

exec docker run --rm $DOCKERRUNOPTIONS $DOCKERADDR $COMPOSEOPTIONS $VOLUMES -w "$(pwd)" $IMAGE "$@"
root@towergame:~/ops-meta/filmtower/COMPOSE#

this is no coincidence: I don't see where COMPOSE_FILE is passed; not to mention it fails when it contains multiple files with separator and paths:

root@towergame:~/ops-meta/filmtower/COMPOSE# COMPOSE_FILE="./docker-compose.yaml:./nginx.yaml" docker-compose --verbose up -d
docker: Error response from daemon: invalid bind mount spec "/root/ops-meta/filmtower/COMPOSE/docker-compose.yaml:.:/root/ops-meta/filmtower/COMPOSE/docker-compose.yaml:.": invalid volume specification: '/root/ops-meta/filmtower/COMPOSE/docker-compose.yaml:.:/root/ops-meta/filmtower/COMPOSE/docker-compose.yaml:.'.
See 'docker run --help'.
root@towergame:~/ops-meta/filmtower/COMPOSE#

Question: Do you plan to fix this and make docker-compose honour COMPOSE_FILE as in docker-compose docs?

Thanks, Herby

1 Answer

I can't edit my question to fix its formatting?!

Have another answer? Share your knowledge.