Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create a MariaDB image in a docker container

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

How to create a MariaDB image in the docker container? for this question, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Create based on commit command mode

Installation of docker

[root@test01 ~] # yum install docker [root@test01 ~] # systemctl enable docker [root@test01 ~] # systemctl start docker

Download the local image

[root@test01 ~] # docker pull centos:7.4.1708 [root@test01 ~] # docker images REPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/centos 7.4.1708 3afd47092a0e 3 months ago 196.6 MB

Create an interactive container

[root@test01] # docker run-it-- name= "mysql_server" centos / bin/bash

Install the mariadb service

[root@e8126d0481d2 /] # yum-y install mariadb-server net-tools

Initialize mariadb

[root@e8126d0481d2 /] # mysql_install_db-- user=mysql

Start the mariadb service in the background

[root@e8126d0481d2 /] # mysqld_safe & [1] 114 [root@e8126d0481d2 /] # 13:45:27 mysqld_safe Logging to'/ var/log/mariadb/mariadb.log'.180210 13:45:27 mysqld_safe Starting mysqld daemon with databases from / var/lib/mysql [root@e8126d0481d2 /] # netstat-tunplActive Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0VOV 3306 0.0.0.0VOV * LISTEN-

Create a mariadb login password and specify an ip login

[root@e8126d0481d2 /] # mysqladmin-u root password '123456' [root@e8126d0481d2 /] # mysql-u root-pEnter password:MariaDB [(none)] > show databases;MariaDB [(none)] > use mysql;MariaDB [mysql] > select Host from user where user='root';MariaDB [mysql] > grant all privileges on *. * to' root'@'%' identified by '123456' with grant option;MariaDB [mysql] > update user set password=password (' 123456') where user='root' and host='e8126d0481d2';MariaDB [mysql] > flush privileges MariaDB [mysql] > exit

Container login verification

[root@e8126d0481d2 /] # mysql-u root-h 172.17.0.2-pEnter password:MariaDB [(none)] > exit

Create a container startup script

[root@e8126d0481d2 ~] # cat run.shrun.shrunxxxxxxxxxxxxxxxxxxxxx

Create a mirror

[root@test01 ~] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESe8126d0481d2 centos "/ bin/bash" 11 minutes ago Exited (0) 8 seconds ago mysql_ server [root @ test01 ~] # docker commit mysql_server mariadb:1.0

Create a container

[root@test01] # docker run-d-p 13306 mariadb:1.0 / root/run.sh [root@test01 ~] # docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESeed3e88a1261 mariadb:1.0 "mysqld_safe" 4 seconds ago Up 3 seconds 0.0.0.0 mariadb:1.0 13306-> 3306/tcp romantic_hamilton

Host login verification

[root@test01 ~] # yum-y install mariadb [root@test01 ~] # mysql-u root-- port=13306-pMariaDB [(none)] >

Create based on Dockerfile mode

Set the creation directory and file [root@test01 ~] # mkdir mariadb_dockerfile & & cd mariadb_ dockerfile [root @ test01 mariadb_dockerfile] # touch db_init.sh [root@test01 mariadb_dockerfile] # touch run.sh Edit Dockerfile and other files Dockerfile [root@test01 mariadb_dockerfile] # cat Dockerfile # basic image FROM centos:7.4.1708# to add author information MAINTAINER liuxin 842887233@qq.com# install mariadb database RUN yum-y install mariadb-server# set environment variable Easy to manage ENV MARIADB_USER rootENV MARIADB_PASS 12345A let the container support Chinese ENV LC_ALL en_US.UTF-8# initialization database ADD db_init.sh / root/db_init.shRUN chmod 775 / root/db_init.shRUN / root/db_init.sh# export port EXPOSE 330 add startup file ADD run.sh / root/run.shRUN chmod 775 / root/run.sh# setting default startup command CMD ["/ root/run. Sh "] db_ init.sh [root @ test01 mariadb_dockerfile] # cat db_init.sh #! / bin/bashmysql_install_db-- user=mysqlsleep 3mysqld_safe & sleep 3#mysqladmin-u" $MARIADB_USER "password" $MARIADB_PASS "mysql-e" use mysql Grant all privileges on *. * to'$MARIADB_USER'@'%' identified by'$MARIADB_PASS' with grant option; "hype $(hostname) mysql-e" use mysql; update user set password=password ('$MARIADB_PASS') where user='$MARIADB_USER' and host='$h'; "mysql-e" flush privileges; "run.sh [root@test01 mariadb_dockerfile] # cat run.sh #! / bin/bashmysqld_safe

Create a mirror

[root@test01 mariadb_dockerfile] # docker build-t liuxin/centos-mariadb:v1. /

Create a container

[root@test01 mariadb_dockerfile] # docker run-d-p 13306 liuxin/centos-mariadb:v1 / root/run.sh [root@test01 mariadb_dockerfile] # docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES7743527ac603 liuxin/centos-mariadb:v1 "/ root/run.sh" 5 seconds ago Up 3 Seconds 0.0.0.0 13306-> 3306/tcp nostalgic_mirzakhani

Login authentication

[root@test01 mariadb_dockerfile] # mysql-uroot-h 127.0.0.1-port=13306-pEnter password: Welcome to the MariaDB monitor. Commands end with; or\ g.Your MariaDB connection id is 1Server version: 5.5.56-MariaDB MariaDB ServerCopyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.MariaDB [(none)] > exit's answer to the question on how to create a MariaDB image in the docker container is here. I hope the above content can be of some help to you. If you still have a lot of questions to solve, you can follow the industry information channel for more relevant knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report