0

I have the same problem like here Docker - failed to mount local volume, no such file or directory

docker-compose --verbose up -d
[+] Running 0/0
 - Container brickchart-mysql-1  Creating                                                                                                                                                                                          0.0s 
Error response from daemon: failed to mount local volume: mount 
.docker/mysql/data:/var/lib/docker/volumes/brickchart_db_volume/_data, 
flags: 0x1000: no such file or directory

Here is my docker-compose.yml file:

version: '3.9'

services:
  mysql:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: db_name
      MYSQL_USER: db_user
      MYSQL_PASSWORD: db_password
    ports:
      - "3306:3306"
    volumes:
      - db_volume:/var/lib/mysql:delegated

volumes:
  db_volume:
    driver: local
    driver_opts:
      type: 'none'
      o: 'bind'
      device: ./.docker/mysql/data

I have the latest Docker Desktop installed:

enter image description here

I also tested older versions: 4.14.0, 4.12.0 and 4.10.1.

I understand that the docker-compose file is converted to docker commands. A verbose flag would help a lot. Unfortunately, it seems like the verbose flag doesn't exist: https://github.com/docker/compose/issues/1640

It would be great if I can see how

volumes:
  - db_volume:/var/lib/mysql:delegated

will be converted in to docker commands.

Does anybody have any tips for this problem?

ThomasL.
  • 83
  • 1
  • 9

2 Answers2

0

This Volume binding using docker compose on Windows helps me to solve my problem.

It must be an absolute path to the host system.

So my solution is right now.

version: '3.9'

services:
  mysql:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: db_name
      MYSQL_USER: db_user
      MYSQL_PASSWORD: db_password
    ports:
      - "3306:3306"
    volumes:
      - db_volume:/var/lib/mysql:delegated

volumes:
  db_volume:
    driver: local
    driver_opts:
      type: 'none'
      o: 'bind'
      device: ${PATH_TO_DB_DATA}

The corresponding .env contains the variable PATH_TO_DB_DATA. Example:

PATH_TO_DB_DATA='/d/path/to/my-project/.docker/mysql/data/'
ThomasL.
  • 83
  • 1
  • 9
0

I'm still struggling with this. I'm running Docker from WSL2. Here's an example of a docker-compose.yml.

version: "3.9"
services:
  db:
    environment:
      POSTGRES_HOST_AUTH_METHOD: trust
    hostname: db
    image: postgres:11.5
    restart: always
    volumes:
      - database:/var/lib/postgresql/data
      - ./deploy/pgsql/certs:/var/lib/postgresql/certs:ro
volumes:
  database:
    driver: local
    driver_opts:
      o: bind
      type: none
      device: ${POSTGRES_DATA_DIR:-./postgres-data}

My .env file looks like this.

COMPOSE_PROJECT_NAME=label-studio
POSTGRES_DATA_DIR=/home/ehansen/label-studio/database

This results in the following error. Note that I removed some services that aren't relevant from the examples above.

(dev) ehansen@BIGBOSS:~/repos/configs/label-studio$ docker-compose up -d
[+] Running 2/3
 ⠿ Container label-studio-db-1     Starting                                                                                                                                                                                                                                                              0.2s 
 ✔ Container label-studio-app-1    Created                                                                                                                                                                                                                                                               0.0s 
 ✔ Container label-studio-nginx-1  Created                                                                                                                                                                                                                                                               0.0s 
Error response from daemon: error while mounting volume '/var/lib/docker/volumes/label-studio_database/_data': failed to mount local volume: mount /run/desktop/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu-22.04/b43b9941a24aea00254d1fad5f6ec9d795b4bde303ed33175b927834a858317e:/var/lib/docker/volumes/label-studio_database/_data, flags: 0x1000: no such file or directory
(dev) ehansen@BIGBOSS:~/repos/configs/label-studio$ 
Eric Hansen
  • 336
  • 2
  • 12