How to run docker-compose on remote host?

After the release of Docker 18.09.0 and the (as of now) upcoming docker-compose v1.23.1 release this will get a whole lot easier. This mentioned Docker release added support for the ssh protocol to the DOCKER_HOST environment variable and the -H argument to docker ... commands respectively. The next docker-compose release will incorporate this feature as well.

First of all, you’ll need SSH access to the target machine (which you’ll probably need with any approach).

Then, either:

# Re-direct to remote environment.
export DOCKER_HOST="ssh://my-user@remote-host"

# Run your docker-compose commands.
docker-compose pull
docker-compose down
docker-compose up

# All docker-compose commands here will be run on remote-host.

# Switch back to your local environment.
unset DOCKER_HOST

Or, if you prefer, all in one go for one command only:

docker-compose -H "ssh://my-user@remote-host" up

One great thing about this is that all your local environment variables that you might use in your docker-compose.yml file for configuration are available without having to transfer them over to remote-host in some way.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)