简体   繁体   中英

docker-compose fails to run on remote host from local

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM