问题
I have an app that is composed of React, Flask, and MongoDB as a database.
What I tried to do was importing (mongoimport) some json files to the MongoDB database when I docker-compose build.
In my root directory, I created a directory called mongo-seed and I put all json files that I tried to import to the database along with the import.sh that looks like:
mongoimport --host <my_host_name> --db <my_db_name> --collection profiles --type json --file /mongo-seed/profiles.json --jsonArray
mongoimport --host <my_host_name> --db <my_db_name> --collection releases --type json --file /mongo-seed/releases.json --jsonArray
mongoimport --host <my_host_name> --db <my_db_name> --collection employees --type json --file /mongo-seed/employees.json --jsonArray
and my docker-compose.yml looks like:
# Docker Compose
version: '3.7'
services:
frontend:
container_name: frontend
build:
context: frontend
dockerfile: Dockerfile
ports:
- "3000:80"
backend:
build: ./backend
ports:
- "5000:5000"
links:
- db
db:
image: mongo:latest
ports:
- "27017:27017"
mongo-seed:
image: mongo:latest
links:
- "db"
volumes:
- ./mongo-seed:/mongo-seed
command:
/mongo-seed/import.sh
However, when I docker-compose build and then docker-compose up, I get
ERROR: for mongo-seed_1 Cannot start service mongo-seed: error while creating mount source path '/host_mnt/c/Users/<...>/Desktop/<root>/mongo-seed': mkdir /host_mnt/c: file exists
ERROR: for mongo-seed Cannot start service mongo-seed: error while creating mount source path '/host_mnt/c/Users/<...>/Desktop/<root>/mongo-seed': mkdir /host_mnt/c: file exists
Am I missing something?
回答1:
This is a known issue/nuisance in the Windows version of Docker. There are multiple things you can try.
- Reset credentials: Even if your password hasn't changed, users have reported that this worked for them. In Settings > Shared Drives, at the bottom there is a button to reset.
- If you don't mind any existing volumes be discarded, you can try
docker-compose up -V <any other options you specify such as -d>. This will recreate anonymous volumes instead of reclaiming old ones. - A simple
docker volume prunehas also worked for some, but this will delete all unused volumes and is not recommended because some of them might have data that you might need to be reclaimed later.
All of the above and more are mentioned in this discussion. The discussion also throws in this useful guide on how to use a directory with Windows' Docker.
来源:https://stackoverflow.com/questions/58264595/mongoimport-in-docker-compose-gives-me-cannot-start-service-error