Hi,
I’ve just discovered --host and --context and it’s wonderful. But there’s one option I’m missing; maybe it’s there and I just can’t find it; maybe I’m doing it wrong; otherwise it’s a feature request =).
How do I make docker-compose --host run within a different project dir on the remote?
The setup
So to illustrate the problem I’ve created minimal project directory for this example-app:
example-app
├── config
│ └── config.txt
├── docker-compose.yaml
└── Dockerfile
The files have the following content:
1: config.txt:
It works!
2: docker-compose.yaml:
version: '2.4'
services:
app:
build:
context: .
volumes:
- "./config:/config"
3: Dockerfile:
FROM busybox:latest
ENTRYPOINT ["cat", "/config/config.txt"]
When I run this locally the ./config directory will be prefixed by my current directory and evaluate as let’s say /home/me/projects/docker/example-app/config:
docker-compose up --build
This is all fine – “It works!”
Going remote
I now want to deploy this to my remote server, aptly called server in this example.
I’ll state the port number 22 explicitly.
First I copy the config dir to the server in an exampleapp-remote dir:
rsync -e "ssh -p 22" -Rav config user@server:exampleapp-remote/
The server now has this structure:
:
home
├── user
: └── exampleapp-remote
└── config
└── config.txt
Now I run docker-compose locally, issuing it to deploy and invoke the app on the server using --host:
docker-compose --host ssh://user@server:22 up --build
And it fails:
app_1 | cat: can't open '/config/config.txt': No such file or directory
Adding --project-directory exampleapp-remote or --project-directory /home/user/exampleapp-remote doesn’t work, as it accounts for the local directory (I guess).
Moving the config dir to the /home/user/config doesn’t work either because the current dir prefix gets evaluated on the host running docker-compose.
What to do?
A --remote-project-directory would be handy here.
Or maybe something like --host ssh://user@server:22/~/exampleapp-remote or --host ssh://user@server:22/home/user/exampleapp-remote.
Or if a --context was used, perhaps a remote-work-dir could be added to the meta.json file.
How do I solve this? How do I make docker-compose --host run within a different project dir on the remote? Is it even doable?