Docker Community Forums

Share and learn in the Docker community.

Import mongo collection on build


(Ayman Nedjmeddine) #1

Is there a way to import collections into a MongoDB during the image build process, please?

My Dockerfile looks something like this:

FROM mongo:3
COPY ./*.json /tmp/
ONBUILD RUN mongoimport -d pfedev -c users --jsonArray < /tmp/users.json
ONBUILD RUN mongoimport -d pfedev -c computers --jsonArray < /tmp/computers.json

That does not work. I’ve tried some other stuff but it did not work either.

Could you, please, help me do it the right way?