Skip to content

Fail to mount and initialise DB with /docker-entrypoint-initdb.d #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sebglon opened this issue Jun 9, 2016 · 18 comments
Closed

Fail to mount and initialise DB with /docker-entrypoint-initdb.d #62

sebglon opened this issue Jun 9, 2016 · 18 comments

Comments

@sebglon
Copy link

sebglon commented Jun 9, 2016

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/* "'

@yosifkit
Copy link
Contributor

yosifkit commented Jun 9, 2016

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)?

@sebglon
Copy link
Author

sebglon commented Jun 10, 2016

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

@sebglon
Copy link
Author

sebglon commented Jun 10, 2016

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.

@blafasel42
Copy link

any news on this? i have the same issue

@yosifkit
Copy link
Contributor

yosifkit commented Aug 3, 2016

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.

@waynetheisinger
Copy link

+1 I've the same issue

@waynetheisinger
Copy link

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

@waynetheisinger
Copy link

though you have to 777 it because it's owned by root, so @yosifkit might be right when he says its probably permissions...

@loranger
Copy link

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 ?

@yosifkit
Copy link
Contributor

Closing old issue. (still think it is/was permissions)

@luandro
Copy link

luandro commented Sep 13, 2017

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.

@yosifkit
Copy link
Contributor

yosifkit commented Sep 13, 2017

@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 docker-library/postgres#203 (comment).

@ratshidaho
Copy link

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.

@jm-ds
Copy link

jm-ds commented Dec 6, 2017

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.

@twogood
Copy link

twogood commented Feb 17, 2018

I solved this by using an absolute path to the docker-entrypoint-initdb.d directory

@florianajir
Copy link

florianajir commented Feb 20, 2018

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

@MartinMuzatko
Copy link

@jm-ds Files are converted to folders if the linux system that docker brings with it, is not able to locate the files correctly.

@MartinMuzatko
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests