1

Via my local I would like to run docker-compose on my remote machine. I have found two ways that should accomplish this but am running into errors.

Fist I am running the following versions:

me:api$ docker-compose  -v
docker-compose version 1.29.2, build unknown
me:api$ docker -v
Docker version 20.10.7, build 20.10.7-0ubuntu5~20.04.2

First way and the way I would prefer for this to work is to the the --context flag. Based on this blog post should be possible.

I created the context like so:

docker context create prod --docker "host=ssh://user@host.com"

I can then run the following and get an output of running containers

docker --context prod ps

However running with docker-compose the command fails

docker-compose --context prod -f docker-compose.yml -f docker-compose.prod.yml up -d
ERROR: Context 'prod' not found

The other option was to use the -H flag based on this SO answer to set the host that I want to execute the commands on. Yes I can SSH into my machine with the user I am using.

docker-compose -H ssh://user@host -f docker-compose.yml -f docker-compose.prod.yml up -d
/bin/sh: 1: ssh: Permission denied
nerdlyist
  • 2,842
  • 2
  • 20
  • 32
  • Please review this unless not done already https://www.docker.com/blog/how-to-deploy-on-remote-docker-hosts-with-docker-compose/ – Soumen Mukherjee Feb 21 '22 at 15:29
  • @SoumenMukherjee that is referenced in the question. – nerdlyist Feb 21 '22 at 15:44
  • Looks like at least the latest `docker compose` is working with DOCKER_HOST like `DOCKER_HOST="ssh://user@host" docker compose logs` does not give the permission denied. – nerdlyist Feb 26 '22 at 05:48

1 Answers1

0

Well it does not look great. I have not been able to get any of the methods to work with docker-compose however there is a new (at the time of writing this) docker compose replacement from docker. The instructions are here. I was hoping that the --context flag would work but it is not found with the new version which leads me to believe that it did not work before. The -H flag lead to the same Permission Denied error as before.

The only way I was able to get this to work was by setting the DOCKER_HOST environment variable.

nerdlyist
  • 2,842
  • 2
  • 20
  • 32