Closed michaelkirk closed 7 months ago
Possible duplicate of https://github.com/pelias/docker/pull/316
Possible duplicate of #303 as well, but this PR also includes some relevant doc updates.
I'd be happy to see either of those merged as an alternative, and I could follow up with the doc changes separately.
Hi @michaelkirk is this working for you? I went to test it today and found it produced an error:
docker compose version
Docker Compose version v2.19.1
STRING='docker compose'
$STRING version
zsh: command not found: docker compose
The other PR seems to suffer the same issue:
DOCKER_COMPOSE_COMMAND="docker compose"
function compose_exec(){ ${DOCKER_COMPOSE_COMMAND} $@; }
compose_exec version
compose_exec: command not found: docker compose
The shell is expecting a single word for the command
followed by zero or more arguments
, I don't believe it's possible to have a multi-word command such as this.
How about this?
function compose_exec(){
if ! command -v docker-compose &> /dev/null
then docker compose $@;
else docker-compose $@;
fi
}
actually, this is probably nicer:
# the 'docker compose' subcommand is now the recommended method of calling compose.
# if not available, we fallback to the legacy 'docker-compose' command.
function compose_exec(){
NATIVE_COMPOSE_VERSION=$(docker compose version 2> /dev/null || true)
if [ -z "$NATIVE_COMPOSE_VERSION" ]; then
docker-compose $@;
else
docker compose $@;
fi
}
It has the advantage of not causing the process to exit if the shell is running with set -x
plus it favours the newer compose method.
It works by attempting to execute docker compose version
and then checking if the output was an empty string or not.
I considered emitting a warning where docker-compose
was installed on the system, but modern versions of Docker Desktop seem to create a symlink which makes that method fragile.
Hi @michaelkirk I've pushed a commit to your branch, could you please test it and let me know if it's good to merge?
Yes, I've been using this code. The error you note seems to be a difference between bash and zsh. Note that cmd/docker.sh
(and the ./pelias
executable) has a shebang: #!/bin/bash
I can indeed reproduce the error you encountered if I change the script to instead run with zsh.
In any case, I'm fine with the version you have pushed as well. Thanks for reviewing!
Here's the reason for this change :rocket:
Fixes error like:
From: https://docs.docker.com/compose/gettingstarted/
Here's what actually got changed :clap:
compose_exec
now first triesdocker compose
before falling back to docker-compose`Alternatively we could just drop docker-compose (v1) support. I confess that I didn't fully test the fallback behavior anyway, and apparently it's no longer supported by docker.
Here's how others can test the changes :eyes:
Run through any of the example projects that utilize a variety of docker compose commands, e.g. portland-metro
closes https://github.com/pelias/docker/pull/303