Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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
like image 630
TheFrozenYoghurt Avatar asked Dec 16 '17 09:12

TheFrozenYoghurt


People also ask

Can Docker compose create volumes?

We can also create a volume with Docker compose service or also specify existing volumes. For example, the following screenshot shows a 'docker-compose' file that creates a docker-compose service with a volume. As a result of the above command, a volume with the name 'myvolume' gets created.

Where does Docker compose create volume?

These volumes are created inside /var/lib/docker/volume local host directory. As we can see, we don't have to specify the host directory. We just need to specify the directory inside the container. If we remove the volume instruction from the docker-compose.


2 Answers

~/.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
like image 136
Vitalii Vitrenko Avatar answered Oct 06 '22 09:10

Vitalii Vitrenko


~ wasn't working for us, it was creating folder called something.json, we fixed it like this:

volumes:
  - /var/run/docker.sock:/var/run/docker.sock
  - ${HOME}/.docker/config.json:/config.json
like image 37
Lesnek Avatar answered Oct 06 '22 10:10

Lesnek