Stop the container (for MySQL) that sets volumes → Start it
$ docker-compose up -d
Creating volume "sample_db-store" with default driver
Creating hoge_db_1 ... error
ERROR: for sample_db_1  Cannot start service db: error while creating mount source path '/host_mnt/Users/~/docker/mysql/sql': mkdir /host_mnt/Users/~/docker/mysql/sql: file exists
ERROR: Encountered errors while bringing up the project.
An error message stating "The host directory cannot be mounted" is displayed and the container cannot be started.
 
 
Docker Desktop for Windows → [Settings] → [Shared Drives] → [Reset Credentials] → Reauthentication (check the corresponding path)
[reference] https://www.nuits.jp/entry/docker-for-windows-mkdir-file-exists
Docker Desktop for Mac → [preferences...] →[Resources] →[File Sharing]
After deleting ** / Users **, [apply & Restart]
Then add ** / Users ** and [apply & Restart]
 
With docker-compose, I was building a MySQL container as follows.
docker-compose.yml
version: '3'
services:
  db:
    image: mysql:8.0
    volumes:
      - db-store:/var/lib/mysql
      - ./logs:/var/log/mysql
      - ./docker/mysql/my.cnf:/etc/mysql/conf.d/my.cnf
      - ./docker/mysql/sql:/docker-entrypoint-initdb.d
    environment:
      - MYSQL_DATABASE=${DB_NAME}
      - MYSQL_USER=${DB_USER}
      - MYSQL_PASSWORD=${DB_PASS}
      - MYSQL_ROOT_PASSWORD=${DB_PASS}
      - TZ=${TZ}
    ports:
      - ${DB_PORT}:3306
volumes: db-store
In volumes, in addition to those related to data and log
docker-compose.yml
 - ./docker/mysql/sql:/docker-entrypoint-initdb.d
Is defined.
In the image for MySQL, when mounting to /docker-entrypoint-initdb.d, the .sql, .sh file existing in the specified host side directory is read and executed when the container is started for the first time. ..
https://hub.docker.com/_/mysql/
Therefore, the SQL for table creation and the shell script for executing SQL were placed in the directory ./docker/mysql/sql on the host side to be mounted on the container. It works without any problem at the first startup. The SQL and shell script I put in between were running without any problems.
However, once the container was stopped with docker-compose stop, this phenomenon occurred at startup with docker-compose up.
I found information that a similar behavior could be solved by deleting the volume, so I tried deleting the container and the named volume.
$ docker-compose down --volumes
Removing sample_db_1    ... done
Removing volume sample_db-store
$ docker-compose up -d
Failure.
Similar Docker Daemon error
docker: Error response from daemon: error while creating mount source path '/host_mnt/c/tmp': mkdir /host_mnt/c: file exists.
Was reported when using Docker Desktop for Windows. However, I couldn't find any reports of similar errors in Docker Desktop for Mac.
It's no good, but the flow is a little different from Windows, but when I tried to imitate the solution of the above error with Docker Desktop for Mac, it worked.
I'm wondering if something went wrong with the Docker Desktop Volumes sharing settings and I couldn't access the directory information on the host side, but I don't know the details.
If you know the root cause, please let me know: qiitan-cry: