In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to create a MariaDB image in docker. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
First, based on commit command to create
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
4. 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 00.0.0.0root@e8126d0481d2 3306 0.0.0.0root@e8126d0481d2-
Create a mariadb login password and specify an ip login
[root@e8126d0481d2 /] # mysqladmin-u root password 'kingsoft' [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 'kingsoft' with grant option;MariaDB [mysql] > update user set password=password (' kingsoft') 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)] >
Second, create based on Dockerfile.
Set up creation directories and files
[root@test01 ~] # mkdir mariadb_dockerfile & & cd mariadb_ docker [root @ test01 mariadb_dockerfile] # touch db_init.sh [root@test01 mariadb_dockerfile] # touch run.sh
Edit files such as Dockerfile
Dockerfile
[root@test01 mariadb_dockerfile] # cat Dockerfile # basic image FROM centos:7.4.1708# used 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 kingsoft# 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 liuxin/centos-mariadb:v1 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 is here to share how to create a MariaDB image in docker. I hope the above content can be helpful to you and learn more. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.