What is the correct syntax for using 'docker compose' when writing a script?

189 Views Asked by At

attempting to run

sudo /usr/local/bin/docker compose exec -T ...

in order to backup a database file

however when referencing documents I see that docker-compose is typically what was there for v1

for v2 what syntax do I have to use so I don't get sudo: /usr/local/bin/docker: command not found

I would like to use the proper v2 version but I don't know how to execute docker compose exec with correct syntax and online documentation is not clear as to why this issue exists or what I should be doing to fix it.

1

There are 1 best solutions below

0
M Stefan Walker On

Just bringing my comment out here as an answer for future readers.

On my system, docker is installed at the location /usr/bin/docker.

The following command works for me

sudo /usr/bin/docker compose --help

and this command

sudo /usr/local/bin/docker compose --help

produces the error sudo: /usr/local/bin/docker: command not found.

Verifying the location of your docker install may help solve this issue.

Since my $PATH includes both bin locations, I used

which docker

to find my install location.


An additional note:

If your install location is in your $PATH (check with echo $PATH), you can use the docker command directly in your shell or scripts.

I usually use a shorter

sudo docker compose --help

which locates the executable for me.