Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker-compose, remote context, path relative to local machine instead of remote

I have a very simple docker-compose.yml:

version: '2.4'

services:
  containername:
    image: ${DOCKER_IMAGE}
    volumes:
      - ./config:/root/config

I'm using a remote staging server accessed via ssh:

docker context create staging --docker "host=ssh://[email protected]"
docker context use staging

However, I see unexpected results with my volume after I docker-compose up:

docker-compose --context staging up -d
docker inspect containername
...
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/Users/crummy/code/.../config",
                "Destination": "/root/config",
                "Mode": "rw",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],
...

It seems the expansion of ./config to a full path happens on the machine docker-compose is running on. Not the machine Docker is running on.

I can fix this problem by hardcoding the entire path: /home/ubuntu/config:/root/config. But this makes my docker-compose file a little less flexible than it could be. Is there a way to get the dot expansion to occur on the remote machine?

like image 496
Malcolm Crum Avatar asked Sep 08 '20 22:09

Malcolm Crum


1 Answers

No, the docs say that:

You can mount a relative path on the host, which expands relative to the directory of the Compose configuration file being used. Relative paths should always begin with . or ..

I believe that happens for two reasons:

  1. There's no easy way and objective way that the docker-compose can find out how to expand . in this context, as there's no way to know what . would mean for the ssh client (home? same folder?).

  2. Even though the docker cli is using a different context, the expansion is done by the docker-compose tool, that's unaware about the context switch.

Even using environment variables might pose a problem, since the env expansion would also happen in the machine you're running the docker-compose command.

like image 109
Gustavo Kawamoto Avatar answered Nov 16 '22 04:11

Gustavo Kawamoto