1

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

I get the following error:

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

Any suggestions? Thanks!

Batmax
  • 253
  • 8
  • 17

1 Answers1

1

Try this :

mongoimport --host 127.0.0.1 --port <specifyPort> -d mydb -c reports --type csv --file mydata.csv --headerline
Atish
  • 4,277
  • 2
  • 24
  • 32
  • Is mongodb running inside the container? What port its running if not on 27017? You need to pass --port explicitly if its not 27017 – Atish Nov 21 '17 at 15:52
  • How can I know if mongodb is running inside the container? Sorry for the noob question, I am completely new to Docker... – Batmax Nov 21 '17 at 15:56
  • docker ps -a, pickup a mongodb containers port from there – Atish Nov 21 '17 at 15:56
  • The point is that when I run the build command from docker (docker build -t mongotest .), the process stops because of the error mentioned above. When listing the containers I see three of them but with no ports attached to them... – Batmax Nov 21 '17 at 16:02
  • whats the mongodb config look like? In the docker image? Whats the port specified? – Atish Nov 21 '17 at 16:06
  • I do not have any mongodb config file actually. I was hoping that just the dockerfile would be enough ? – Batmax Nov 21 '17 at 16:09
  • check if this helps: https://stackoverflow.com/questions/45876216/connect-to-mongodb-running-inside-docker – Atish Nov 21 '17 at 16:15
  • Thank for the link, I needed to run mongod --smallfiles before using mongoimport! – Batmax Nov 22 '17 at 10:27
  • glad to know that! – Atish Nov 22 '17 at 10:29