Tearing my hair out for 7 hours trying to get mongodb deployed in a container on Debian 12. I have done a stack of dev work locally with mongodb in a container and no issues.
I have a bind mounted local directory mounted on /docker-entrypoint-initdb.d/ with two .js files. I scp’d these from my local MacOS machine to the Debian VPS. I used these files in local dev to see the DB, set up a user etc. Now when I start the docker container on a fresh deployment (ie. /data/db non existent, I let the container create it) I get the error in the logs:
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
I have gone into the container and verified the .js files exist:
root@1368a82ab4a5:/# ls -la /docker-entrypoint-initdb.d/
total 16
drwxrwx--- 2 ubuntu 1001 4096 Jun 29 11:21 .
drwxr-xr-x 1 root root 4096 Jun 29 11:21 ..
-rw-r--r-- 1 ubuntu 1001 309 Jun 29 11:21 01-mongo-init.js
-rw-r--r-- 1 ubuntu 1001 713 Jun 29 11:21 02-tokens.js
The error: /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/* cannily come from one code block in /usr/local/bin/docker-entrypoint.sh:
for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.js) echo "$0: running $f"; "${mongo[@]}" "$MONGO_INITDB_DATABASE" "$f"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done
The error being that the case statement does not find a .js file. However, I am in the container and copy and pasted that same code block (with a small modification for the .js case outcome) and it runs and finds my .js files. Again… this is inside the container.
root@1368a82ab4a5:/# for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.js) echo "$0: running $f";;
*) echo "$0: ignoring $f" ;;
esac
echo
done
bash: running /docker-entrypoint-initdb.d/01-mongo-init.js
bash: running /docker-entrypoint-initdb.d/02-tokens.js
root@1368a82ab4a5:/#
This is my docker-compose.yml file:
services:
mongodb:
image: mongo:latest
container_name: mongodb
restart: unless-stopped
volumes:
- ./mongodb/data:/data/db/
- ./mongodb/initdb.d:/docker-entrypoint-initdb.d/:ro
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE}
ports:
- "27017:27017"
Not sure what to do from here.