mongoimport Docker失败:连接到数据库服务器时出错:没有可访问的服务器

问题描述:

我正在尝试使用MongoDB创建一个Docker容器并将数据导入其中.我尝试使用以下dockerfile:

I am trying to create a Docker container with MongoDB and import data into it. I have tried using the following dockerfile:

FROM mongo

# This will be created if it doesn't exist
WORKDIR /app/data/

# Copy dependency definitions
COPY mydata.csv .

ENTRYPOINT mongod

# Import data
RUN mongoimport --host=127.0.0.1 -d mydb -c reports --type csv --file mydata.csv --headerline

我收到以下错误:

Failed: error connecting to the db server: no reachable servers

有什么建议吗?谢谢!

尝试一下:

mongoimport --host 127.0.0.1 --port <specifyPort> -d mydb -c reports --type csv --file mydata.csv --headerline