Mysql docker container

From Elexis-Wiki
Jump to navigation Jump to search

Howto create a MySQL Docker container for Elexis

Here we show you howto create a MySQL docker container running MySQL Version 5.7 using the dump my_elexis_dump.sql. The database may be accessed via port 1400 and is called my_elexis. Adapt these value to your needs.


You need a working installation of docker and docker-compose

Create needed files

We assume use hier /path/to as base directory any place the following files there

  • dump/my_elexis_dump.sql
  • config/lower_case.cnf which contains
  • docker-compose.yml which contains
	version: '2.0'
	    container_name: myelexis_mysql
	    image: mysql:5.7
	    restart: always
	      MYSQL_DATABASE: my_elexis
	      MYSQL_ROOT_PASSWORD: elexisTest
	      MYSQL_USER: 'elexis'
	      MYSQL_PASS: 'elexisTest'
	      - 1400:3306 # Yverdon has PLZ 1400
	      - /path/to:/var/lib/mysql 
	      - /path/to/dump:/docker-entrypoint-initdb.d
	      - /path/to/config:/etc/mysql/conf.d

Start and config the database

Now you should be able to start the database by running docker-compose -f /path/to/docker-compose.yml up

This will take some time, because loading the dump takes some time. Once you see in the output the line [Note] mysqld: ready for connections. you should be able to use the database. Now stop the docker-compose up command. Use docker-compose -f /path/to/docker-compose.yml start to start it without logging to the standard output.

I don't know why the specified mysql user elexis is not created correctly and does not have the permissions to acess via localhost. Therefore I ran the following command

	mysql --host=localhost --user=root --password=elexisTest --protocol=tcp --port=1400
	Welcome to the MariaDB monitor.  Commands end with ; or \g.
	Your MySQL connection id is 3
	Server version: 5.7.19 MySQL Community Server (GPL)
	Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
	Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
	MySQL [(none)]> create user elexis identified by 'elexisTest';
	Query OK, 0 rows affected (0.00 sec)
	MySQL [(none)]> GRANT ALL PRIVILEGES ON `my_elexis`.* TO 'my_elexis'@'%' ;
	Query OK, 0 rows affected (0.00 sec)

Now I am able to connect normally using mysql --host=localhost --user=elexis --password=elexisTest --protocol=tcp --port=1400 my_elexis

Start Elexis using the new database

Elexis3 -consoleLog -vmargs -Dch.elexis.dbUser=elexis -Dch.elexis.dbPw=elexisTest -Dch.elexis.dbFlavor=mysql -Dch.elexis.dbSpec=jdbc:mysql://localhost:1400/my_elexis

Dumping the new database

This can be done docker-compose -f /mnt/qnap/downloads/db_dumps/bruno/docker-compose.yml exec db mysqldump --user=root --password=elexisTest --single-transaction --add-drop-table my_elexis >my_new_dump.sql