if i set sql file on $(pwd)/init-db, and run this command
docker run -v $(pwd)/init-db:/docker-entrypoint-initdb.d -e MYSQL_ROOT_PASSWORD=tutu
-e MYSQL_DATABASE=tutu -e MYSQL_PASSWORD=tutu mariadb
Mariadb ignore file /docker-entrypoint-initdb.d
"/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/* "'
So, init-db is a directory with a file ending in .sql? Is the directory and file readable by user 999 (which is what the sql process runs as)?
Yes init-db is a directory with file endind in .sql ans .sh. this directory is readable by docker an mounter on container with root '770'.
For information this don't work on Mysql but work with postgres images
After than container is started and file is ignored, if i make this command, file is imported:
mysql -u $MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE < /docker-entrypoint-initdb.d/file.sql
The .sql file is read and imported on my database.
any news on this? i have the same issue
It has to be permissions on the files in the initdb directory. The only difference for this part between the mariadb and postgres entrypoint scripts is that postgres is still running as the root user when it runs the scripts while mariadb/mysql is running as the mysql user in the container.
+1 I've the same issue
if you create your own dockerfile that use extend FROM this mariadb base image and use an ADD to copy the file into the images container it works... but it doesn't work when you load it as a volume
though you have to 777 it because it's owned by root, so @yosifkit might be right when he says its probably permissions...
Having the same issue.
I'm not even able to achieve the solution provided by @waynetheisinger.
The only solution I found is to run a bash session within the image and inject my /docker-entrypoint-initdb.d/dump.sql manually.
Is there another way ?
Closing old issue. (still think it is/was permissions)
Having the same issue... Should be a better explanation on how to use. Here's my docker-compose.yml:
version: '2'
services:
wordpress:
image: wordpress:latest
restart: always
volumes:
- ./config/php.conf.uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
- ./wp-app:/var/www/html # Full wordpress project
environment:
WORDPRESS_DB_PASSWORD: '${DB_PASSWORD}'
mysql:
image: mariadb:latest
restart: always
volumes:
- ./wp-data:/docker-entrypoint-initdb.d
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
Inside ./wp-data/ there's a .sql dump file.
@luandro, what are the permissions of that file and folder from inside the sql container? The scripts/sql files in /docker-entrypoint-initdb.d/ are run by the mysql user of the container, so they need to be readable by that user.
Or possibly related to https://github.com/docker-library/postgres/issues/203#issuecomment-255200501.
Hi there.
I had the same issue, and all I did was to give the full path to my local folder that I am mounting and it worked.
I'm having this exact issue on win 7 with toolbox but not on the unbuntu 17 where the image is built. What's odd in my case is that the files appear to be converted to directories when moved from Ubuntu to windows. I just saved the image and reloaded on windows and then ran docker-compose up -d.
When I bash into the image and ls -l inside docker-entrypoint-initdb.d I get the following:
drwxrwxrwx 2 root root 40 Dec 5 23:04 OnPremise.sql
drwxrwxrwx 2 root root 40 Dec 5 23:04 mysql-setup.sql
======== UPDATE ========
I was able to get my instance to work by using COPY in a Dockerfile instead of using volume from within docker-compose.yml. There's definitely something not right now the volume mounts seeing as it converted my files to directories when moved from Ubuntu to windows. I am, however, on Win 7 using Docker toolbox.
I solved this by using an absolute path to the docker-entrypoint-initdb.d directory
If your container has been initialized before you put sql dump in share volume of your docker-compose.yml you need to remove the volume and recreate the container to restart initialisation process:
docker volume ls
docker volume rm your_volume_name
@jm-ds Files are converted to folders if the linux system that docker brings with it, is not able to locate the files correctly.
I found the problem: As @florianajir correctly suggested: The files are only then read, when the container is created anew!
This solved the problem for me.
Most helpful comment
any news on this? i have the same issue