Nethence Newdoc Olddoc Lab Your IP BBDock  

Setting up a MariaDB container

Introduction

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,

app=mariadbprod
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)
pwgen

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

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

app=mariadbprod
docker ps -a | grep $app
docker run -d --name $app -h $app \
    -p 3306:3306 \
    -v /data/$app:/var/lib/mysql \
    -e MYSQL_ROOT_PASSWORD=PASSWORD_HERE \
    mariadb
docker ps -a | grep $app
docker logs $app

Setup some database

Setup the database e.g ‘somedb’,

app=mariadbprod
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,

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

and check,

app=mariadbprod
docker exec -ti $app mysql -usomedbuser -pUSERPASS_HERE somedb
show databases;
use somedb;
show tables;
^D

Network Access

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

app=tmpcheckmaria
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;
^D

Maintenance / Operations

Operating Docker Containers

References

Alt References about SQlite & enhancements


Home | GitHub | Donate | Contact