docker-compose中的mongoimport给我'无法启动服务'错误 [英] mongoimport in docker-compose gives me 'Cannot start service' error
问题描述
我有一个由React,Flask和MongoDB组成的应用程序作为数据库。
I have an app that is composed of React, Flask, and MongoDB as a database.
我试图做的是导入( mongoimport
)当我 docker-compose build
时将一些json文件添加到MongoDB数据库中。
What I tried to do was importing (mongoimport
) some json files to the MongoDB database when I docker-compose build
.
在我的根目录中,创建了一个名为 mongo-seed
的目录,并将尝试导入的所有json文件与一起放入数据库中。 import.sh
类似于:
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
和我的 docker-compose.yml
看起来像:
# 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
但是,当我 docker-compose build
然后 docker-compose up
,我得到
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
我错过了什么吗?
推荐答案
这是Windows版本Docker中的一个已知问题/麻烦。您可以尝试多种操作。
This is a known issue/nuisance in the Windows version of Docker. There are multiple things you can try.
- 重置凭据:即使您的密码没有更改,用户也报告说这对他们有用。在设置>共享驱动器底部,有一个按钮可以重置。
- 如果您不介意丢弃任何现有卷,则可以尝试
docker-组成-V<您指定的任何其他选项,例如-d>
。 - 一个简单的
docker volume prune
也适用于某些匿名卷,但是它将删除所有未使用的卷,因此不建议使用,因为其中一些可能包含您稍后需要回收的数据。
- 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 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.
以上所有在此讨论中,提到了更多。讨论还会在如何在Windows的Docker中使用目录。
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.
这篇关于docker-compose中的mongoimport给我'无法启动服务'错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!