[DOCKER] What to do if error while creating mount source path'/ host_mnt / Users / ~': mkdir / host_mnt / Users / ~: file exists when the container starts

phenomenon

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.

Operating environment

  

Solutions

If you are using Docker Desktop for Windows

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

If you are using Docker Desktop for Mac

Docker Desktop for Mac → [preferences...] →[Resources] →[File Sharing]

After deleting ** / Users **, [apply & Restart]

Then add ** / Users ** and [apply & Restart]

What I tried before solving

Operating background

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.

Tried (1): Delete volume

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.

Tried (2): Update the authentication information of the shared folder of Docker Desktop for Mac (this solution)

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.

Cause

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:

Recommended Posts

What to do if error while creating mount source path'/ host_mnt / Users / ~': mkdir / host_mnt / Users / ~: file exists when the container starts
What to do if you get a "Cannot Pull Container Error" when starting ECS ​​Fargate
[Ruby] What to do when the error "cannot load such file" appears when executing VS Code debug
What to do if an error occurs when nokogiri enters when bundle install
What to do if you get an error when you hit Heroku logs
What to do if you get an "A server is already running." Error when you try to start the rails server
What to do if you get the error message unrecognized selector send to instance "***"
What to do if the changes are not reflected in the jar manifest file
[Grails] Error occurred running What to do when the Grails CLI does not start
What to do if the server tomcat dies
What to do when debugging "Source not found"
What to do if you get the error Couldn't find Item without an ID
What to do if you get a port error when docker-compose up on Mac
What to do if the debug gem installation fails
What to do if the Rails server can't start
What to do when The SSL certificate has expired
What to do if ClassNotFoundException occurs when starting Tomcat
What to do when a null byte error occurs
What to do when rails creates a 〇〇 2.rb file
What to do if an ActionController :: UnknownFormat error occurs
Error ExecJS :: RuntimeUnavailable: What to do when it occurs
What to do if you don't see the test code error message in the terminal console
What to do if a SAX Parser error occurs when using Liferay 7 / DXP on AWS
[Rails] What to do if you can't get an error message with the errors method
What to do if the adb command cannot be executed
What to do if mysql2 gets a bundle install error
What to do if you can't use the rails command
[Rails] What to do when the error No database selected and Unknown database appears in db: migrate
What to do if you go offline due to SSL certificate error when running Jenkins on Mac
[Programming beginner] What to do when rails s becomes an error in the local development environment
What to do when you want to know the source position where the method is defined in binding.pry
What to do if you get a JNI shared library error when trying to build in Eclipse
What to do about the "cannot be read or is not a valid ZIP file" error
What to do if the app is not created with the latest Rails version installed when rails new
What to do if an error occurs when doing npm install axios in React + Typescript project