您好,登錄后才能下訂單哦!
這篇“Docker如何創(chuàng)建MariaDB鏡像”文章的知識點大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細,步驟清晰,具有一定的借鑒價值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“Docker如何創(chuàng)建MariaDB鏡像”文章吧。
[root@test01 ~]# yum install docker[root@test01 ~]# systemctl enable docker[root@test01 ~]# systemctl start docker
[root@test01 ~]# docker pull centos:7.4.1708[root@test01 ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE docker.io/centos 7.4.1708 3afd47092a0e 3 months ago 196.6 MB
[root@test01 ~]# docker run -it --name="mysql_server" centos /bin/bash
[root@e8126d0481d2 /]# yum -y install mariadb-server net-tools
[root@e8126d0481d2 /]# mysql_install_db --user=mysql
[root@e8126d0481d2 /]# mysqld_safe &[1] 114 [root@e8126d0481d2 /]#180210 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.0:3306 0.0.0.0:* LISTEN -
創(chuàng)建mariadb登錄密碼,并可以指定ip登錄
[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
[root@e8126d0481d2 /]# mysql -u root -h 172.17.0.2 -pEnter password: MariaDB [(none)]> exit
[root@e8126d0481d2 ~]# cat run.sh#!/bin/shmysqld_safe
[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
[root@test01 ~]# docker run -d -p 13306:3306 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:13306->3306/tcp romantic_hamilton
[root@test01 ~]# yum -y install mariadb[root@test01 ~]# mysql -u root --port=13306 -pMariaDB [(none)]>
設(shè)置創(chuàng)建目錄和文件 [root@test01 ~]# mkdir mariadb_dockerfile && cd mariadb_dockerfile[root@test01 mariadb_dockerfile]# touch db_init.sh[root@test01 mariadb_dockerfile]# touch run.sh編輯Dockerfile等文件 Dockerfile [root@test01 mariadb_dockerfile]# cat Dockerfile#使用的基礎(chǔ)鏡像FROM centos:7.4.1708#添加作者信息MAINTAINER liuxin 842887233@qq.com#安裝mariadb數(shù)據(jù)庫RUN yum -y install mariadb-server#設(shè)置環(huán)境變量,便于管理ENV MARIADB_USER root ENV MARIADB_PASS 123456#讓容器支持中文ENV LC_ALL en_US.UTF-8#初始化數(shù)據(jù)庫ADD db_init.sh /root/db_init.sh RUN chmod 775 /root/db_init.sh RUN /root/db_init.sh#導(dǎo)出端口EXPOSE 3306#添加啟動文件ADD run.sh /root/run.sh RUN chmod 775 /root/run.sh#設(shè)置默認啟動命令CMD ["/root/run.sh"] db_init.sh [root@test01 mariadb_dockerfile]# cat db_init.sh#!/bin/bashmysql_install_db --user=mysql sleep 3 mysqld_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;"h=$(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
[root@test01 mariadb_dockerfile]# docker build -t liuxin/centos-mariadb:v1 ./
[root@test01 mariadb_dockerfile]# docker run -d -p 13306:3306 liuxin/centos-mariadb:v1 /root/run.sh[root@test01 mariadb_dockerfile]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7743527ac603 liuxin/centos-mariadb:v1 "/root/run.sh" 5 seconds ago Up 3 seconds 0.0.0.0:13306->3306/tcp nostalgic_mirzakhani
[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 1 Server version: 5.5.56-MariaDB MariaDB Server Copyright (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
以上就是關(guān)于“Docker如何創(chuàng)建MariaDB鏡像”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對大家有幫助,若想了解更多相關(guān)的知識內(nèi)容,請關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。