Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker-compose can't find compose files #34

Closed
rmeissn opened this issue Jul 16, 2020 · 2 comments
Closed

docker-compose can't find compose files #34

rmeissn opened this issue Jul 16, 2020 · 2 comments

Comments

@rmeissn
Copy link

rmeissn commented Jul 16, 2020

I got a setup where a webhook script executes docker-compose and uses a custom compose file inside the same directory. So my script looks like:

#!/bin/bash

DIR=$(dirname $0)
cd $DIR

docker-compose -f ./docker-compose-staging.yml ps
docker-compose -f ./docker-compose-staging.yml pull
docker-compose -f ./docker-compose-staging.yml up -d --force-recreate

With version 1.8.0 of webhookd, the script executes just fine. With any later version (e.g. v1.9.0), docker-compose always reports that it is unable to find the specified compose file. This is even the case when I declare the whole path to the compose file inside the container, by e.g. docker-compose -f /scripts/tmp/docker-compose-staging.yml ps.

@ncarlier
Copy link
Owner

Hi,

last Docker image use this script as a wrapper command for Docker Compose (in order to reduce the image size). This script will use Compose Docker image (Docker in Docker). In order to mount the file in the container, you must therefore specify the location of the Compose file on the host.

In your case:

$ # Start Webhookd Docker container
$ docker run -d --name=webhookd \
  -v /var/run/docker.sock:/var/run/docker.sock  \
  -v ${PWD}/scripts:/var/opt/webhookd/scripts \
  -e "COMPOSE_OPTIONS=-v $PWD/docker-compose-staging.yml:/docker-compose.yml" \
  -p 8080:8080 \
  ncarlier/webhookd \
  webhookd --scripts=/var/opt/webhookd/scripts

Note the COMPOSE_OPTIONS env variable. This variable is used by the script to add options to docker-compose command.
You can then simplify your script in this way:

#!/bin/bash

docker-compose ps
docker-compose pull
docker-compose -d --force-recreate

NB: you can also declare COMPOSE_OPTIONS inside your script but don't forget to use the host absolute path.

@pataquets
Copy link

Watch out for differences in the execution environment (user, variables, etc.) between your user context and webhookd's context. Specially (but not restricted to) PATH variable, ie. provide full path for docker-compose.

@ncarlier ncarlier closed this as completed Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants