mongoimport in docker-compose gives me 'Cannot start service' error

烂漫一生 提交于 2019-12-13 03:47:18

问题


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.

  1. 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.
  2. 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.
  3. A simple docker volume prune has 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!