Nethence Newdoc Olddoc Lab Your IP BBDock  

Setting up a MariaDB container


Fetch / Update the official image

Fetch or update the MariaDB image and check,

docker pull mariadb:latest
docker images

Launch the container

Make sure the data folder doesn’t exist yet otherwise the init part that follows doesn’t make sense,

sudo ls -alhF /data/$app/
#sudo rm -rf /data/$app/

Generate a strong password that you would copy/paste to replace PASSWORD_HERE and USERPASS_HERE,

#sudo apt install pwgen (Ubuntu)
sudo yum install pwgen (CentOS/RHEL EPEL needed)

and write it someplace so you don’t loose it.

Launch a MariaDB container mapping volume /data/mariadbprod/ to /var/lib/mysql/ and check.

docker ps -a | grep $app
docker run -d --name $app -h $app \
    -p 3306:3306 \
    -v /data/$app:/var/lib/mysql \
docker ps -a | grep $app
docker logs $app

Setup some database

Setup the database e.g ‘somedb’,

docker exec -ti $app mysql -uroot -pPASSWORD_HERE

create database somedb;
grant all privileges on somdb.* to somedbuser identified by 'USERPASS_HERE';
flush privileges;

eventually inject some shit into it,

docker exec -ti $app mysql -usomedbuser -pUSERPASS_HERE somedb < ~/schema.sql

and check,

docker exec -ti $app mysql -usomedbuser -pUSERPASS_HERE somedb
show databases;
use somedb;
show tables;

Network Access

Check that you can access that DB from another container. Note. connecting to host defined by the –link :alias (here mariadb).

docker run -ti --name $app -h $app --link mariadbprod:mariadb custom/ubuntu bash
cat /etc/hosts
ping -c1 mariadb
nc -z -v mariadb 3306
apt -y update && apt -y install mariadb-client
mysql -uroot -pPASSWORD_HERE -h mariadb
show databases;
use somedb;
show tables;

Maintenance / Operations

Operating Docker Containers


Alt References about SQlite & enhancements

Home | GitHub | Docker Hub | Donate | Contact