I have been struggling to configure the execution of scripts via /docker-entrypoint-initdb.d in a Mongo container in Docker.
I have tried to follow the documentation carefully, but without success.
project structure
docker-compose.yml
version: '3.3'
services:
mongodb:
image: mongo:latest
container_name: mongo_db
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: rootpass
MONGO_INITDB_DATABASE: database
volumes:
- mongodbdata:/data/db
- ./init.d/:/docker-entrypoint-initdb.d/
restart: always
volumes:
mongodbdata:
driver: local
init-mongo.sh
#!/bin/bash
echo 'hello script'
In the logs the command echo 'hello script' is not executed.
What should I do? Is there something I'm missing?
Docker only executes scripts inside docker-entrypoint-initdb.d
upon creation of the image as this is mostly used for seeding data. If it's not a fresh image and you're just trying to spawn it again with your script then that's what caused it.
What you can try to do is type this in your terminal:
docker stop $(docker ps -aq) && docker rm $(docker ps -aq) && docker rmi mongo:latest -f && docker-compose up
Then check the logs:P
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.