At the root of the project is the docker-compose.yum file :

version: '3.5' services: db: container_name: my_db image: mysql ports: - "3306:3306" volumes: - "mysql:/var/lib/mysql" environment: MYSQL_ROOT_PASSWORD: 12345 MYSQL_DATABASE: test MYSQL_USER: vlad MYSQL_PASSWORD: 12345 volumes: mysql: 

After docker-compose up -d --build , a corresponding volume is created on the host in the directory: / var / lib / docker / volumes /

Question: How can I change this default address to my own? Those. I want this volume to be created not by the address / var / lib / docker / volumes / , but by the address, for example, / home / vlad / my_project / mysql . I want to store all project files in one place!

    1 answer 1

    For a named volume - in any way, but instead of a volume you can mount an arbitrary directory on the host:

     volumes: - /home/etki/Workspace/playground/mysql:/var/lib/mysql 

    At the same time, keep in mind that the docker is acting as the root user, and all created files and directories will belong to him.