MariaDB / mariadb-docker

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

MYSQL_DATABASE does not create database #68

Closed rosshettel closed 8 years ago

rosshettel commented 8 years ago

Seems like this is not working for me according to the docs. I have this in my docker-compose.yml file:

librenms_db:
    image: mariadb
    container_name: librenms_db
    restart: always
    environment:
        - MYSQL_ROOT_PASSWORD=*******
        - MYSQL_DATABASE=librenms
    volumes:
        - /srv/librenms/db:/var/lib/mysql

Here's the logs on startup:

Creating network "docker_default" with the default driver
Creating librenms_db
Attaching to librenms_db
librenms_db    | 2016-07-09 17:58:43 140123011254208 [Note] mysqld (mysqld 10.1.14-MariaDB-1~jessie) starting as process 1 ...
librenms_db    | 2016-07-09 17:58:43 140123011254208 [Note] InnoDB: Using mutexes to ref count buffer pool pages
librenms_db    | 2016-07-09 17:58:43 140123011254208 [Note] InnoDB: The InnoDB memory heap is disabled
librenms_db    | 2016-07-09 17:58:43 140123011254208 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
librenms_db    | 2016-07-09 17:58:43 140123011254208 [Note] InnoDB: Memory barrier is not used
librenms_db    | 2016-07-09 17:58:43 140123011254208 [Note] InnoDB: Compressed tables use zlib 1.2.8
librenms_db    | 2016-07-09 17:58:43 140123011254208 [Note] InnoDB: Using Linux native AIO
librenms_db    | 2016-07-09 17:58:43 140123011254208 [Note] InnoDB: Using SSE crc32 instructions
librenms_db    | 2016-07-09 17:58:43 140123011254208 [Note] InnoDB: Initializing buffer pool, size = 256.0M
librenms_db    | 2016-07-09 17:58:43 140123011254208 [Note] InnoDB: Completed initialization of buffer pool
librenms_db    | 2016-07-09 17:58:43 140123011254208 [Note] InnoDB: Highest supported file format is Barracuda.
librenms_db    | 2016-07-09 17:58:43 140123011254208 [Note] InnoDB: 128 rollback segment(s) are active.
librenms_db    | 2016-07-09 17:58:43 140123011254208 [Note] InnoDB: Waiting for purge to start
librenms_db    | 2016-07-09 17:58:43 140123011254208 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.29-76.2 started; log sequence number 1616935
librenms_db    | 2016-07-09 17:58:43 140122221676288 [Note] InnoDB: Dumping buffer pool(s) not yet started
librenms_db    | 2016-07-09 17:58:43 140123011254208 [Note] Plugin 'FEEDBACK' is disabled.
librenms_db    | 2016-07-09 17:58:43 140123011254208 [Note] Server socket created on IP: '::'.
librenms_db    | 2016-07-09 17:58:43 140123011254208 [Warning] 'proxies_priv' entry '@% root@559cb30e132b' ignored in --skip-name-resolve mode.
librenms_db    | 2016-07-09 17:58:43 140123011254208 [Note] mysqld: ready for connections.
librenms_db    | Version: '10.1.14-MariaDB-1~jessie'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution

But then when I list the databases inside the container, the librenms database is not there:

docker exec -it librenms_db bash
root@0f9eea832748:/# echo $MYSQL_DATABASE
librenms
root@0f9eea832748:/# mysql -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.1.14-MariaDB-1~jessie mariadb.org binary distribution

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
thaJeztah commented 8 years ago

I see you're bind-mounting a directory (/srv/librenms/db), is this the first time you run a container using this directory? Was the directory empty before running the container? (the image will only initialize the database if the data directory is empty; see this line in the entrypoint script; https://github.com/docker-library/mariadb/blob/cc686f56875aa84d135bb89de6ca50385211bdab/10.1/docker-entrypoint.sh#L36)

rosshettel commented 8 years ago

Ah thanks for pointing that out. The directory already existed as I ran the container earlier without the env variable set, so that's why it didn't get created on startup. I'll close this then, thanks again!

thaJeztah commented 8 years ago

You're welcome!

On 10 Jul 2016, at 03:56, Ross Hettel notifications@github.com wrote:

Ah thanks for pointing that out. The directory already existed as I ran the container earlier without the env variable set, so that's why it didn't get created on startup. I'll close this then, thanks again!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

danielecr commented 5 years ago

well no. It does not work.

In fact this is my composer:

services:
    mariadb:
        image: mariadb
        volumes:
            - ./dbdata:/docker-entrypoint-initdb.d
        environment:
            - MYSQL_ROOT_PASSWORD=rootte
            - MYSQL_DATABASE=sswsuitecrm
            - MYSQL_USER=sswsuitecrm
            - MYSQL_PASSWORD=suitepwd

and

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.001 sec)

on first run

same when running with a void folder

danielecr commented 5 years ago

sorry, still checking this. It looks like database initialization take looooooong time, more than what i expected.

Anyway I hope it is usefull my comment to anyone facing this problem with little patience like me

LeDOC666 commented 4 years ago

Hello, I have the same problem, (And I think waited so much) Here is my command: docker run -d --name wp-mysql --network wp-network -v /data/wordpress/mysql:/var/lib/mysql -e MYSQL_USER=wordpress_user -e MYSQL_PASSWORD=wp_passmord -e MYSQL_DATABASE=wordpress -e MYSQL_RANDOM_ROOT_PASSWORD=1 mariadb

I deleted all /data/wordpress/mysql/* before, and still no database created !?

LeDOC666 commented 4 years ago

ok, I have to wait 30 min :+1:

yosifkit commented 4 years ago

@LeDOC666, that sounds like https://github.com/docker-library/mariadb/issues/262.

gezichenshan commented 4 years ago

Hi, my compose file is like:

version: "2"
services:
  mariadb_local:
    build:
      context: ./src
      dockerfile: mariadb-dockerfile
      args:
        MYSQL_DATABASE: dev
        MYSQL_ROOT_PASSWORD: dev
    container_name: mariadb_local
    restart: always
    ports:
      - 3306:3306
    volumes:
      - ./mariadb/data:/data
    environment:
      MYSQL_DATABASE: dev
      MYSQL_ROOT_PASSWORD: dev

and mariadb-dockerfile:

FROM mariadb

ADD dev.sql /docker-entrypoint-initdb.d

And I didn't see the dev DB created when I exec into mysql container.

P.S. I added build args because I see the doc says If your service specifies a build option, variables defined in environment are not automatically visible during the build. Use the args sub-option of build to define build-time environment variables. but still have no specified MYSQL_DATABASE created.

What am I missing?

gezichenshan commented 4 years ago

I checked this solution and saved my life. He changed the volumn name and worked! The answer says it might the data layer might not be recreated.

Could you give some detailed info?

danielecr commented 4 years ago

https://docs.docker.com/engine/reference/builder/#add yes, probably it was this missing:

If <dest> does not end with a trailing slash, it will be considered a regular file and the contents of <src> will be written at <dest>

so this line

ADD dev.sql /docker-entrypoint-initdb.d

should have been

ADD dev.sql /docker-entrypoint-initdb.d/

EDIT: the . in documentation is meant as the end of the sentence, nothing to do with . directory!

gezichenshan commented 4 years ago

@danielecr Thanks! You are right that I made a mistake forgot to add a slash in the end.

And another thing I think it is the build command in docker-compose file will only be executed at the first time when you do docker-compose up. The image will not be rebuilt the second time you type the same command. So if the first time the config is wrong in your dockerfile, you input docker-compose up then the wrong layer is added to the image. And the second time you will get same wrong result though you've changed the dockerfile.

So you should rebuild the image first and then up the container: type docker-compose build | docker-compose up to explicitly tell the docker to rebuild the image. Then the docker image layer will be changed and you will probably get desired result.

It is just a guess. I didn't verify it.

danielecr commented 4 years ago

yes, that is also true. A shorter version is docker-compose --build up (all on doc https://docs.docker.com/compose/reference/up/ as usual)

Shadow8472 commented 1 year ago

I see you're bind-mounting a directory (/srv/librenms/db), is this the first time you run a container using this directory? Was the directory empty before running the container? (the image will only initialize the database if the data directory is empty; see this line in the entrypoint script; https://github.com/docker-library/mariadb/blob/cc686f56875aa84d135bb89de6ca50385211bdab/10.1/docker-entrypoint.sh#L36)

Thank you for this key piece of advice. I've been pruning volumes instead of fully removing them while trying to get a Nextcloud pod assembly script together. I found leftover gunk in my volume from an earlier attempt. Thank you so much!

podman volume rm \<volumeName>