Machine: Docker machine remote working directory

Created on 9 Mar 2017  路  2Comments  路  Source: docker/machine

I'm not sure this is a docker-machine or docker-compose issue, but will try to explain it.

I have to following compose file:

services:
    db:
      image: postgres
      volumes:
          - .pgdata:/var/lib/postgresql/data
   .... more services...

I run docker-compose and and docker-machine the commands from my laptop.
The local laptop user is goetas and the folder where is stored the application on my laptop is /home/goetas/projects/events.

When running:

eval $($docker machine env my-machine)
docker-compose up

On the remore hosts (my-machine) the container is created, and the a folder /home/goetas/events/.pgdata has been created (to store the database data).

No user goetas has been created on the remote host, only a folder.
From what I could guess, the naming strategy is /home/[LOCAL-USER]/[LOCAL-FOLDER-NAME].

My question is: Is there a way to configure the folder that is used as working directory when running the container?

Most helpful comment

But in general, remote bind mounts won't "just work"

I'm not interested in sharing data between my laptop and the remote machine, so i'm not trying to do a remote mount

You can specify the absolute path of the remote host in the first part of the bind mount.

This will introduce a correlation/dependency between the remote machine and the docker-compose.yml (and this is how I solved the problem at the moment).

The problem that I'm trying to highlight here is that is not clear how /home/[LOCAL-USER]/[LOCAL-FOLDER-NAME] is obtained.
Relying in the local username and folder name is something that introduce a dependency to factors that can not be controlled (can not force the user to use a specific username or to deploy from a specific folder...).

To summarize:

  • current behavior: path generated based on local factors (/home/[LOCAL-USER]/[LOCAL-FOLDER-NAME]) is risky because not possible to control them
  • your proposed solution: hard code paths in the docker-compose.yml works but introduce a one-to-one relation between docker-compose.yml and the remote host

In my opinion it will make more sense to have some parameter to decide where the working directory... In the example of the docker-compose use something as /var/docker/[COMPOSE-PROJECT-NAME] as default (project-name can be configured via -p parameter in docker-compose).

To me is not yet clear if this is a docker machine or docker compose issue since I could not figure out which component decides the path, for that reason I have create the same issue also here https://github.com/docker/compose/issues/4598

All 2 comments

Is there a way to configure the folder that is used as working directory when running the container?

You can specify the absolute path of the remote host in the first part of the bind mount. But in general, remote bind mounts won't "just work"

But in general, remote bind mounts won't "just work"

I'm not interested in sharing data between my laptop and the remote machine, so i'm not trying to do a remote mount

You can specify the absolute path of the remote host in the first part of the bind mount.

This will introduce a correlation/dependency between the remote machine and the docker-compose.yml (and this is how I solved the problem at the moment).

The problem that I'm trying to highlight here is that is not clear how /home/[LOCAL-USER]/[LOCAL-FOLDER-NAME] is obtained.
Relying in the local username and folder name is something that introduce a dependency to factors that can not be controlled (can not force the user to use a specific username or to deploy from a specific folder...).

To summarize:

  • current behavior: path generated based on local factors (/home/[LOCAL-USER]/[LOCAL-FOLDER-NAME]) is risky because not possible to control them
  • your proposed solution: hard code paths in the docker-compose.yml works but introduce a one-to-one relation between docker-compose.yml and the remote host

In my opinion it will make more sense to have some parameter to decide where the working directory... In the example of the docker-compose use something as /var/docker/[COMPOSE-PROJECT-NAME] as default (project-name can be configured via -p parameter in docker-compose).

To me is not yet clear if this is a docker machine or docker compose issue since I could not figure out which component decides the path, for that reason I have create the same issue also here https://github.com/docker/compose/issues/4598

Was this page helpful?
0 / 5 - 0 ratings