Search code examples
docker-compose

How can I create a volume for the current user home directory in docker-compose?


For the docker image v2tec/watchtower I must provide the user-specific docker configuration file config.json. I am currently doing this as following:

version: "3"
services:
    watchtower:
    image: v2tec/watchtower
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /home/thefrozenyoghurt/.docker/config.json:/config.json

This works on my machine. But I want to distribute this docker-compose.yml to my colleagues so they can use it also. This won't work with the docker-compose.yml above, as my home directory is hardcoded.

Is it possible to refer to the user home directory in a docker-compose.yml? I cannot find such functionalities in the documentation. I think I need something like:

version: "3"
services:
    watchtower:
    image: v2tec/watchtower
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - $HOME/.docker/config.json:/config.json

Solution

  • ~/.docker/config.json should work for this

    version: "3"
    services:
      watchtower:
        image: v2tec/watchtower
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock
          - ~/.docker/config.json:/config.json