I'm trying to add an init.sh
script to the docker-entrypoint-initdb.d
so I can finish provisioning my DB in a docker container. The script is in a scripts
directory in my local directory where the Dockerfile
lives. The Dockerfile
is simply:
FROM glats/alpine-lamp
ENV MYSQL_ROOT_PASSWORD=password
The build command works and completes with no errors, and then when I try to run the container it also runs fine, with the linked volume with the init script:
docker run -d --name mydocker -p 8080:80 -it mydocker \
-v ~/Docker/scripts:/docker-entrypoint-initdb.d
However when I log into the running container, I don't see any docker-entrypoint-initdb.d
directory, and obviously the init.sh
never runs:
/ # ls /
bin etc media proc sbin tmp
dev home mnt root srv usr
entry.sh lib opt run sys var
Does anyone know why the volume isn't getting mounted?
There is no such logic defined in the Docker image that you are using, the entrypoint of the above image just starts MySQL and httpd and does not any ability to construct Database from entrypoint.
If you want to have the ability to run init script using mysql-entrypoint and construct the database you need to use offical image.
When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions
.sh, .sql and .sql.gz
that are found in/docker-entrypoint-initdb.d
.
Also running container, better to use one process per container. you can look into this docker-compose file that runs the stack as per rule of container "one process per container"