Collated the document today to build mariadb
Host or CentOS 172.16.0.200 build a second images
mkdir./mysql-dockerfile Below is three files
Dockerfile #构建mariadb-images
mysqld_charset.cnf #mariadb #配置文件 The encoding format is set
Script #目录内, storing three files
Script #目录下三个文件
All right, let's take a look at one.
Dockerfile
From docker.io/<237356573@qq .com>#add system-/var/lib/Yum Install -y mariadb mariadb-server &&yum clean all#add Mysql.confadd mysqld_charset.cnf /etc/my.cnf.d//chmod +x/script/ Start
MYSQLD_CHARSET.CNF #设置mysql Encoding Configuration
[mysqld]character_set_server=utf8character_set_filesystem=utf8collation-server=utf8_general_ciinit-connect= ' Set NAMES UTF8 ' init_connect= ' set collation_connection = Utf8_general_ci '
/script/start
if Then # config mariadb /script/run_maria rm /script/MarkElse # Cleanup Previous mariadb sockets ifthen rm -F ${ data_dir}/mysql.sock fifi/usr/bin/mysqld_safe
Run_maria initial mariadb user password ....
#!/bin/Bashdb_user=${db_user:-Admin} Db_pass=${db_pass:-Admin} Mariadb_new=true# # MariaDB Setup#run_maria () {# FirstInstallmariadbif[[!-D ${data_dir}/mysql]]; ThenEcho "===> MariaDB not install ..."Echo "===> Initializing Maria database ..."mysql_install_db--user=mysql--ldata=${data_dir}Echo "===> System databases initialized ..."# Start Mariadb/usr/bin/mysqld_safe--user mysql >/dev/NULL 2>&1&Echo "===> waiting for MariaDB to start ..."STA=1 while[[Sta-ne0]]; Doprintf"."Sleep 5MySQL-uroot-e"Status">/dev/NULL 2>&1STA=$? DoneEcho "===> Start OK ..."# 1. Create a localhost-Only admin Accountmysql-U root-e"CREATE USER ' $DB _user ' @ '% ' identified by ' $DB _pass '"MySQL-U root-e"CREATE USER ' $DB _user ' @ ' localhost ' identified by ' $DB _pass '"MySQL-U root-e"CREATE USER ' $DB _user ' @ ' 127.0.0.1 ' identified by ' $DB _pass '"MySQL-U root-e"GRANT All privileges on * * to ' $DB _user ' @ '% ' with GRANT OPTION"Echo "===> Create localhost completed ..."# shutdown MARIADB towait forSupervisormysqladmin-u root shutdownElseif[[-E ${data_dir}/mysql.sock]]; ThenRM-F ${data_dir}/Mysql.sockfimariadb_new=falseEcho "===> Using An existing volume of MariaDB"fi}run_maria
Okay, now start build images
Take a look at the local base image:
Docker images
Docker build-t Python-mysql:mariadb-v1.
After the build is complete, see images
Docker images
To start the container:
Docker run--name python-sql-d-P 3306:3306 python-mysql:mariadb-v1
Navicat_mysql Connection Test
Don't forget: Setenforce 0
Docker builds open source CMDB platform step by step: DockerFile Build mariadb