mongorestore in Dockerfile not locating dump files

Viewed 171

Been trying to land this Dockerfile to work properly but seems there's no human way for me to do so.

The directory where the Dockerfile is placed looks like this:

my_dir
  |
  |- Dockerfile
  |- samplesdb
  |- samplesdb/samples.bson
  |- samplesdb/samples_metadata.json

Now, the Dockerfile looks like this:

FROM mongo

COPY . /dump/

WORKDIR /dump

CMD mongorestore --host 127.0.0.1 --port 27017 --db samplesdb --drop samples

However, it will always Failed: mongorestore target 'dump' invalid: stat dump: no such file or directory.

Is there any reason for this? How should I copy those dumps?

1 Answers

mongorestore looks for a dump directory in your current directory, if it is named something else, you need to explicitly specify it as the last argument.

Your COPY command is creating /dump/samplesdb, however, mongorestore expects the bson files to be at the root of the dump directory

So, change the below line:

CMD mongorestore --host 127.0.0.1 --port 27017 --db samplesdb --drop samples

to (notice the samplesdb - your custom dump directory - as the last argument)

CMD mongorestore --host 127.0.0.1 --port 27017 --db samplesdb --drop samples samplesdb
Related