I am trying to run a mysql container in docker compose by using:
version: "3.3"
services:
mysql:
image: "mysql:8.0.3"
volumes:
# files are executed in alphabetical order
- ./test/data/music_schema.sql:/docker-entrypoint-initdb.d/1-music_schema.sql
- ./test/data/beatles.sql:/docker-entrypoint-initdb.d/2-beatles.sql
The purpose of this, is that these .sql files should be executed once the containers starts, and it should load the data into the database. These files are mounted properly, as in: I can see them inside the container, but they show weird permissions (i.e all exclamation marks.):
root@0b24fb573b55:/# ls -lh /docker-entrypoint-initdb.d/
ls: cannot access /docker-entrypoint-initdb.d/2-beatles.sql: Input/output error
ls: cannot access /docker-entrypoint-initdb.d/1-music_schema.sql: Input/output error
total 0
-????????? ? ? ? ? ? 1-music_schema.sql
-????????? ? ? ? ? ? 2-beatles.sql
regardless of this, the data is indeed loaded in the database, so apparently the mysql entry point doesn't realy care about how this files are mounted, as it's executing them anyways:
mysql> use music;
Database changed
mysql> show tables;
+-----------------+
| Tables_in_music |
+-----------------+
| Album |
| Artist |
| Membership |
| Songwriter |
| Track |
+-----------------+
5 rows in set (0.00 sec)
so the data is indeed loaded. I am doing this in macos Catalina.
The weird thing is that I try the exact same thing in another Ubuntu server (same docker-compose, same files, basically a clone of the repo), and the files instead of being mounted as ??????
they are mounted as directories:
ls -lha /docker-entrypoint-initdb.d/
total 16K
drwxr-xr-x 1 root root 4.0K May 2 06:12 .
drwxr-xr-x 1 root root 4.0K May 2 06:12 ..
drwxr-xr-x 2 root root 4.0K May 2 05:26 1-music-schema.sql
drwxr-xr-x 2 root root 4.0K May 2 05:26 2-beatles.sql
this is of course not loading any data into the mysql server, and the container crashes in ubuntu.
Why is this happening? how can I specify to mount files into files instead of files into directories? I followed other answers in here and to me it looks like I am doing the right way, but maybe I am missing something else.