Making a Dockerfile to bundle a microservices project with a MongoDB instance. I get an error about EOF
missing in my script. The code is based on the official MongoDB entry-point script.
ENTRYPOINT echo '#!/bin/bash\n\
pidfile="${TMPDIR:-/tmp}/docker-entrypoint-temp-mongod.pid" \n\
rm -f "$pidfile" \n\
mongod --logpath /var/log/mongodb.log --dbpath /data/db/ --fork --pidfilepath "$pidfile" \n\
mongo=( mongo --host 127.0.0.1 --port 27017 --quiet ) \n\
# check to see that our "mongod" actually did start up (catches "--help", "--version", MongoDB 3.2 being silly, slow prealloc, etc) \n\
# https://jira.mongodb.org/browse/SERVER-16292 \n\
tries=30 \n\
while true; do \n\
if ! { [ -s "$pidfile" ] && ps "$(< "$pidfile")" &> /dev/null; }; then \n\
# bail ASAP if "mongod" is not even running \n\
echo >&2 \n\
echo >&2 "error: mongod does not appear to have stayed running -- perhaps it had an error?" \n\
echo >&2 \n\
exit 1 \n\
fi \n\
if mongo admin --eval "quit(0)" &> /dev/null; then \n\
# success! \n\
break \n\
fi \n\
(( tries-- )) \n\
if [ "$tries" -le 0 ]; then \n\
echo >&2 \n\
echo >&2 "error: mongod does not appear to have accepted connections quickly enough -- perhaps it had an error?" \n\
echo >&2 \n\
exit 1 \n\
fi \n\
sleep 1 \n\
done \n\
mongo -- admin <<-EOF \n\
db.createUser({user:"user", pwd:"admin123", roles:[{role:"root", db:"admin"}]}); \n\
EOF ' >> ./init_mongo.sh && cat ./init_mongo.sh && chmod +x ./init_mongo.sh && ./init_mongo.sh && /opt/myproject/start.sh all
When I run the container, it gives the below error:
about to fork child process, waiting until server is ready for connections.
forked process: 13
child process started successfully, parent exiting
./init_mongo.sh: line 28: warning: here-document at line 26 delimited by end-of-file (wanted `EOF')
MongoDB shell version v3.4.22
connecting to: mongodb://127.0.0.1:27017/admin
MongoDB server version: 3.4.22
Successfully added user: {
"user" : "user",
"roles" : [
{
"role" : "root",
"db" : "admin"
}
]
}
2019-09-10T11:45:05.776+0000 E QUERY [thread1] ReferenceError: EOF is not defined :
@(shell):1:1
bye
Just in case, I even cat
the script and see nothing wrong with it. Any ideas/suggestions? Seems like maybe a missing or trailing whitespace or something... Checked whatever I could think of...
Thank you