docker-composedocker-volumeddev

DDEV/docker-compose: Bind-mount a path with an absolute path


I'm trying to define a volume in ddev like this:

Filename: docker-compose.salesforce.yaml

Contents:

version: '3.6'
services:
  web:
    volumes:
      - /Users/dmgig/JWT:/home/dmgig/JWT:rw

But as you can see it uses my user name and I'd like to make it work for anyone.

I've tried to find a home directory variable, but can't find one.

I assumed something like:

version: '3.6'
services:
  web:
    volumes:
      - $HOME/JWT:$HOME_DDEV/JWT:rw

How would I write this so that it uses the correct paths for the host and the ddev machine?


Solution

  • You're trying to mount ~/JWT from the host into ~/JWT inside the container?

    The environment variables are evaluated on the host by docker-compose, which doesn't know anything about what's inside the container, so you'll need to use absolute paths for inside the container, as you already did.

    I think this might work for you on Linux or macOS:

    services:
      web:
        volumes:
          - /Users/$USER/JWT:/home/$USER/JWT:rw