I have compose file locally. How to run bundle of containers on remote host like docker-compose up -d
with DOCKER_HOST=
?
Given that you are able to log in on the remote machine, another approach to running docker-compose
commands on that machine is to use SSH
.
Copy your docker-compose.yml
file over to the remote host via scp
, run the docker-compose
commands over SSH
, finally clean up by removing the file again.
This could look as follows:
scp ./docker-compose.yml SomeUser@RemoteHost:/tmp/docker-compose.yml
ssh SomeUser@RemoteHost "docker-compose -f /tmp/docker-compose.yml up"
ssh SomeUser@RemoteHost "rm -f /tmp/docker-compose.yml"
You could even make it shorter and omit the sending and removing of the docker-compose.yml
file by using the -f -
option to docker-compose
which will expect the docker-compose.yml
file to be piped from stdin
. Just pipe its content to the SSH
command:
cat docker-compose.yml | ssh SomeUser@RemoteHost "docker-compose -f - up"
If you use environment variable substitution in your docker-compose.yml
file, the above-mentioned command will not replace them with your local values on the remote host and your commands might fail due to the variables being unset. To overcome this, the envsubst utility can be used to replace the variables with your local values in memory before piping the content to the SSH
command:
envsubst < docker-compose.yml | ssh SomeUser@RemoteHost "docker-compose up"