From 4552b78deba6043d2c9607192f91ba56ce4afdf3 Mon Sep 17 00:00:00 2001 From: Joeseph Rodrigues Date: Thu, 17 Aug 2017 13:03:08 -0600 Subject: [PATCH 1/3] add mongodb-tools We now have access to the various tools for working with mongodb, imcluding mongoimport and mongoexport. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 03d9bb6..2dc06ad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM alpine:edge RUN \ -apk add --no-cache mongodb && \ +apk add --no-cache mongodb mongodb-tools && \ rm /usr/bin/mongoperf VOLUME /data/db From 041443624695e09f65ba1144fea5e0a2f7b96fea Mon Sep 17 00:00:00 2001 From: Joeseph Rodrigues Date: Thu, 17 Aug 2017 14:59:36 -0600 Subject: [PATCH 2/3] try a default data import on build --- Dockerfile | 3 +++ import.sh | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100755 import.sh diff --git a/Dockerfile b/Dockerfile index 2dc06ad..89fb1a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,9 @@ rm /usr/bin/mongoperf VOLUME /data/db EXPOSE 27017 28017 +COPY import.sh /root +RUN /root/import.sh + COPY run.sh /root ENTRYPOINT [ "/root/run.sh" ] CMD [ "mongod" ] diff --git a/import.sh b/import.sh new file mode 100755 index 0000000..0bfc0be --- /dev/null +++ b/import.sh @@ -0,0 +1,6 @@ +FILE="/data/db/default.json" + +if [ -e $FILE ]; then + echo "Importing $FILE" + mongoimport --file $FILE +fi From 5388cce51ab03fbb45c891668af4be847b1fd452 Mon Sep 17 00:00:00 2001 From: Joeseph Rodrigues Date: Thu, 17 Aug 2017 15:46:53 -0600 Subject: [PATCH 3/3] import script doesnt work as expected I would like the auto import to slurp up any data provided by a volume in a docker-compose setup, and the method I wrote didnt seem to be working. Now trying in the entrypoint --- Dockerfile | 3 --- import.sh | 6 ------ run.sh | 8 ++++++++ 3 files changed, 8 insertions(+), 9 deletions(-) delete mode 100755 import.sh diff --git a/Dockerfile b/Dockerfile index 89fb1a0..2dc06ad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,9 +7,6 @@ rm /usr/bin/mongoperf VOLUME /data/db EXPOSE 27017 28017 -COPY import.sh /root -RUN /root/import.sh - COPY run.sh /root ENTRYPOINT [ "/root/run.sh" ] CMD [ "mongod" ] diff --git a/import.sh b/import.sh deleted file mode 100755 index 0bfc0be..0000000 --- a/import.sh +++ /dev/null @@ -1,6 +0,0 @@ -FILE="/data/db/default.json" - -if [ -e $FILE ]; then - echo "Importing $FILE" - mongoimport --file $FILE -fi diff --git a/run.sh b/run.sh index cfc0fa8..b9d0b7d 100755 --- a/run.sh +++ b/run.sh @@ -1,4 +1,12 @@ #!/bin/sh + +# import any default data +FILE="/data/db/default.json" +if [ -e $FILE ]; then + echo "Importing $FILE" + mongoimport --file $FILE +fi + # Docker entrypoint (pid 1), run as root [ "$1" = "mongod" ] || exec "$@" || exit $?