MariaDB / mariadb-docker

Docker Official Image packaging for MariaDB
https://mariadb.org
GNU General Public License v2.0
755 stars 436 forks source link

Creating new container ignores enviroment variables #534

Closed mattdale77 closed 8 months ago

mattdale77 commented 8 months ago

I am creating a new mariadb container with the latest tag. It seems to ignore all the environment variables that I set. I'll include my docker compose below but root password is not set, no user created and no database created. I have tried with both the MYSQL and MARIADB variants

version: "3" services: db: image: mariadb:latest container_name: db restart: unless-stopped environment:

grooverdan commented 8 months ago

environment variables are ignored when there is a data directory already installed.

https://mariadb.com/kb/en/mariadb-server-docker-official-image-environment-variables/

mattdale77 commented 8 months ago

This is a brand new database. Nothing is already installed. /mnt/db in my example does not even yet exist

mattdale77 commented 8 months ago

Interestingly this works ok with a named volume. It seems to think that if using a bind mount means that a data directory already exists, even if it has to create that directory.

It does not work if I use a named volume with type local and option bind. Even if the bind directory is empty

mattdale77 commented 8 months ago

I thought I would get around this by using /docker-entrypoint-initdb.d however the script in here is not run, I'm assuming for the same reasons that the environment variables are ignored.

grooverdan commented 8 months ago

What I get with your yaml file (using /tmp/db as volume created as a directory) is:

$ docker-compose up
Creating network "tmp_default" with the default driver
Creating db ... done
Attaching to db
db    | 2023-10-17 22:27:50+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.1.2+maria~ubu2204 started.
db    | find: ‘/var/lib/mysql/’: Permission denied
db    | chown: changing ownership of '/var/lib/mysql/': Permission denied
db exited with code -1

After appending :Z to the volume entry (for selinux permission).

$ docker-compose up
Recreating db ... done
Attaching to db
db    | 2023-10-17 22:29:25+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.1.2+maria~ubu2204 started.
db    | 2023-10-17 22:29:25+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db    | 2023-10-17 22:29:25+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.1.2+maria~ubu2204 started.
db    | 2023-10-17 22:29:26+00:00 [Note] [Entrypoint]: Initializing database files
...
db    | Version: '11.1.2-MariaDB-1:11.1.2+maria~ubu2204'  socket: '/run/mysqld/mysqld.sock'  port: 0  mariadb.org binary distribution
db    | 2023-10-17 22:29:27+00:00 [Note] [Entrypoint]: Temporary server started.
db    | 2023-10-17 22:29:27+00:00 [Note] [Entrypoint]: Creating database testdb
db    | 2023-10-17 22:29:27+00:00 [Note] [Entrypoint]: Creating user testuser
db    | 2023-10-17 22:29:27+00:00 [Note] [Entrypoint]: Giving user testuser access to schema testdb

I get the same result removing the /tmp/db directory on start.

After creating a /mnt/db directory, fixing its ownership like:

docker run --rm  -v /mnt/db:/var/lib/mysql:Z mariadb:latest chown mysql: /var/lib/mysql

Changing the compose to:

    user: mysql
    entrypoint: bash -x -v /usr/local/bin/docker-entrypoint.sh mariadbd

Then you can see what path the entrypoint took.

You'll note that https://docs.docker.com/compose/compose-file/07-volumes/ uses named volumes.

mattdale77 commented 8 months ago

There did seem to be a slight permission issue but I have resolved this with the user command in the docker-compose and by adding /etc/passwd and /etc/group as volumes. It now creates the files with the correct ID.

When I run I get the following:

dbtest | 2023-10-18 00:36:57+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.1.2+maria~ubu2204 started.

dbtest | 2023-10-18 00:36:57+00:00 [Note] [Entrypoint]: Initializing database files dbtest | dbtest | dbtest | PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER ! dbtest | To do so, start the server, then issue the following command: dbtest | dbtest | '/usr/bin/mariadb-secure-installation' dbtest | dbtest | which will also give you the option of removing the test dbtest | databases and anonymous user created by default. This is dbtest | strongly recommended for production servers. dbtest | dbtest | See the MariaDB Knowledgebase at https://mariadb.com/kb dbtest | dbtest | Please report any problems at https://mariadb.org/jira dbtest | dbtest | The latest information about MariaDB is available at https://mariadb.org/. dbtest | dbtest | Consider joining MariaDB's strong and vibrant community: dbtest | https://mariadb.org/get-involved/ dbtest | dbtest | 2023-10-18 00:40:47+00:00 [Note] [Entrypoint]: Database files initialized dbtest | 2023-10-18 00:40:47+00:00 [Note] [Entrypoint]: Starting temporary server dbtest | 2023-10-18 00:40:47+00:00 [Note] [Entrypoint]: Waiting for server startup dbtest | 2023-10-18 0:40:47 0 [Note] Starting MariaDB 11.1.2-MariaDB-1:11.1.2+mariaubu2204 source revision 9bc25d98209df6810f7a7d5e7dd3ae677a313ab5 as process 82 dbtest | 2023-10-18 0:40:47 0 [Note] InnoDB: Compressed tables use zlib 1.2.11 dbtest | 2023-10-18 0:40:47 0 [Note] InnoDB: Using transactional memory dbtest | 2023-10-18 0:40:47 0 [Note] InnoDB: Number of transaction pools: 1 dbtest | 2023-10-18 0:40:47 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions dbtest | 2023-10-18 0:40:47 0 [Note] mariadbd: O_TMPFILE is not supported on /tmp (disabling future attempts) dbtest | 2023-10-18 0:40:47 0 [Note] InnoDB: Using liburing dbtest | 2023-10-18 0:40:47 0 [Note] InnoDB: Initializing buffer pool, total size = 128.000MiB, chunk size = 2.000MiB dbtest | 2023-10-18 0:40:47 0 [Note] InnoDB: Completed initialization of buffer pool dbtest | 2023-10-18 0:40:47 0 [Note] InnoDB: Buffered log writes (block size=512 bytes) dbtest | 2023-10-18 0:40:47 0 [Note] InnoDB: End of log at LSN=47241 dbtest | 2023-10-18 0:40:47 0 [Note] InnoDB: Opened 3 undo tablespaces dbtest | 2023-10-18 0:40:47 0 [Note] InnoDB: 128 rollback segments in 3 undo tablespaces are active. dbtest | 2023-10-18 0:40:47 0 [Note] InnoDB: Setting file './ibtmp1' size to 12.000MiB. Physically writing the file full; Please wait ... dbtest | 2023-10-18 00:41:18+00:00 [ERROR] [Entrypoint]: Unable to start server. dbtest | 2023-10-18 00:41:19+00:00 [Note] [Entrypoint]: MariaDB upgrade not required dbtest | 2023-10-18 0:41:19 0 [Note] Starting MariaDB 11.1.2-MariaDB-1:11.1.2+mariaubu2204 source revision 9bc25d98209df6810f7a7d5e7dd3ae677a313ab5 as process 1 dbtest | 2023-10-18 0:41:19 0 [Note] InnoDB: Compressed tables use zlib 1.2.11 dbtest | 2023-10-18 0:41:19 0 [Note] InnoDB: Using transactional memory dbtest | 2023-10-18 0:41:19 0 [Note] InnoDB: Number of transaction pools: 1 dbtest | 2023-10-18 0:41:19 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions dbtest | 2023-10-18 0:41:19 0 [Note] mariadbd: O_TMPFILE is not supported on /tmp (disabling future attempts) dbtest | 2023-10-18 0:41:19 0 [Note] InnoDB: Using liburing dbtest | 2023-10-18 0:41:19 0 [Note] InnoDB: Initializing buffer pool, total size = 128.000MiB, chunk size = 2.000MiB dbtest | 2023-10-18 0:41:19 0 [Note] InnoDB: Completed initialization of buffer pool dbtest | 2023-10-18 0:41:19 0 [Note] InnoDB: Buffered log writes (block size=512 bytes) dbtest | 2023-10-18 0:41:19 0 [Note] InnoDB: End of log at LSN=47241 dbtest | 2023-10-18 0:41:19 0 [Note] InnoDB: Opened 3 undo tablespaces dbtest | 2023-10-18 0:41:19 0 [Note] InnoDB: 128 rollback segments in 3 undo tablespaces are active. dbtest | 2023-10-18 0:41:19 0 [Note] InnoDB: Removed temporary tablespace data file: "./ibtmp1" dbtest | 2023-10-18 0:41:19 0 [Note] InnoDB: Setting file './ibtmp1' size to 12.000MiB. Physically writing the file full; Please wait ... dbtest | 2023-10-18 0:42:06 0 [Note] InnoDB: File './ibtmp1' size is now 12.000MiB. dbtest | 2023-10-18 0:42:06 0 [Note] InnoDB: log sequence number 47241; transaction id 14 dbtest | 2023-10-18 0:42:06 0 [Note] Plugin 'FEEDBACK' is disabled. dbtest | 2023-10-18 0:42:06 0 [Note] Plugin 'wsrep-provider' is disabled. dbtest | 2023-10-18 0:42:06 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool dbtest | 2023-10-18 0:42:06 0 [Note] InnoDB: Cannot open '/var/lib/mysql/ib_buffer_pool' for reading: No such file or directory dbtest | 2023-10-18 0:42:06 0 [Note] Server socket created on IP: '0.0.0.0'. dbtest | 2023-10-18 0:42:06 0 [Note] Server socket created on IP: '::'. dbtest | 2023-10-18 0:42:06 0 [Warning] 'user' entry 'root@980db9e1ccda' ignored in --skip-name-resolve mode. dbtest | 2023-10-18 0:42:06 0 [Warning] 'proxies_priv' entry '@% root@980db9e1ccda' ignored in --skip-name-resolve mode. dbtest | 2023-10-18 0:42:06 0 [Note] mariadbd: Event Scheduler: Loaded 0 events dbtest | 2023-10-18 0:42:06 0 [Note] mariadbd: ready for connections. dbtest | Version: '11.1.2-MariaDB-1:11.1.2+maria~ubu2204' socket: '/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution

grooverdan commented 8 months ago

Ah, the old 30 seconds to write a 12MB file issue - #485 has a work around.

mattdale77 commented 8 months ago

So do I set the innodb_temp_data_file_path as an environment variable or another way?

grooverdan commented 8 months ago
command: --innodb_temp_data_file_path=/dev/shm/ibtmp1:12M:autoextend
mattdale77 commented 8 months ago

Thank you very much. This resolved my issue. For the record, my bind mount was in fact on an NFS. Since this issue is being tracked elsewhere I'll close this

grooverdan commented 8 months ago

Short of a NFS server on the Moon, I still haven't got a good reason why NFS takes so long for this small amount of data. I guess I'm going to have to set it up myself. Waiting for someone to resolve it for me isn't working particularly well :smiling_face_with_tear: .

mattdale77 commented 8 months ago

Best of luck. I'll keep an eye out for a fix but I have a work around which is satisfactory