Docker如何创建MariaDB镜像
这篇“Docker如何创建MariaDB镜像”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Docker如何创建MariaDB镜像”文章吧。
[root@test01~]#yuminstalldocker[root@test01~]#systemctlenabledocker[root@test01~]#systemctlstartdocker下载本地镜像
[root@test01~]#dockerpullcentos:7.4.1708[root@test01~]#dockerimagesREPOSITORYTAGIMAGEIDCREATEDSIZEdocker.io/centos7.4.17083afd47092a0e3monthsago196.6MB创建交互型容器
[root@test01~]#dockerrun-it--name="mysql_server"centos/bin/bash安装mariadb服务
[root@e8126d0481d2/]#yum-yinstallmariadb-servernet-tools初始化mariadb
[root@e8126d0481d2/]#mysql_install_db--user=mysql后台启动mariadb服务
[root@e8126d0481d2/]#mysqld_safe&[1]114[root@e8126d0481d2/]#18021013:45:27mysqld_safeLoggingto'/var/log/mariadb/mariadb.log'.18021013:45:27mysqld_safeStartingmysqlddaemonwithdatabasesfrom/var/lib/mysql[root@e8126d0481d2/]#netstat-tunplActiveInternetconnections(onlyservers)ProtoRecv-QSend-QLocalAddressForeignAddressStatePID/Programnametcp000.0.0.0:33060.0.0.0:*LISTEN-
创建mariadb登录密码,并可以指定ip登录
[root@e8126d0481d2/]#mysqladmin-urootpassword'123456'[root@e8126d0481d2/]#mysql-uroot-pEnterpassword:MariaDB[(none)]>showdatabases;MariaDB[(none)]>usemysql;MariaDB[mysql]>selectHostfromuserwhereuser='root';MariaDB[mysql]>grantallprivilegeson*.*to'root'@'%'identifiedby'123456'withgrantoption;MariaDB[mysql]>updateusersetpassword=password('123456')whereuser='root'andhost='e8126d0481d2';MariaDB[mysql]>flushprivileges;MariaDB[mysql]>exit容器登录验证
[root@e8126d0481d2/]#mysql-uroot-h172.17.0.2-pEnterpassword:MariaDB[(none)]>exit创建容器启动脚本
[root@e8126d0481d2~]#catrun.sh#!/bin/shmysqld_safe创建镜像
[root@test01~]#dockerps-aCONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMESe8126d0481d2centos"/bin/bash"11minutesagoExited(0)8secondsagomysql_server[root@test01~]#dockercommitmysql_servermariadb:1.0创建容器
[root@test01~]#dockerrun-d-p13306:3306mariadb:1.0/root/run.sh[root@test01~]#dockerpsCONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMESeed3e88a1261mariadb:1.0"mysqld_safe"4secondsagoUp3seconds0.0.0.0:13306->3306/tcpromantic_hamilton主机登录验证
[root@test01~]#yum-yinstallmariadb[root@test01~]#mysql-uroot--port=13306-pMariaDB[(none)]>基于Dockerfile方式创建
设置创建目录和文件[root@test01~]#mkdirmariadb_dockerfile&&cdmariadb_dockerfile[root@test01mariadb_dockerfile]#touchdb_init.sh[root@test01mariadb_dockerfile]#touchrun.sh编辑Dockerfile等文件Dockerfile[root@test01mariadb_dockerfile]#catDockerfile#使用的基础镜像FROMcentos:7.4.1708#添加作者信息MAINTAINERliuxin842887233@qq.com#安装mariadb数据库RUNyum-yinstallmariadb-server#设置环境变量,便于管理ENVMARIADB_USERrootENVMARIADB_PASS123456#让容器支持中文ENVLC_ALLen_US.UTF-8#初始化数据库ADDdb_init.sh/root/db_init.shRUNchmod775/root/db_init.shRUN/root/db_init.sh#导出端口EXPOSE3306#添加启动文件ADDrun.sh/root/run.shRUNchmod775/root/run.sh#设置默认启动命令CMD["/root/run.sh"]db_init.sh[root@test01mariadb_dockerfile]#catdb_init.sh#!/bin/bashmysql_install_db--user=mysqlsleep3mysqld_safe&sleep3#mysqladmin-u"$MARIADB_USER"password"$MARIADB_PASS"mysql-e"usemysql;grantallprivilegeson*.*to'$MARIADB_USER'@'%'identifiedby'$MARIADB_PASS'withgrantoption;"h=$(hostname)mysql-e"usemysql;updateusersetpassword=password('$MARIADB_PASS')whereuser='$MARIADB_USER'andhost='$h';"mysql-e"flushprivileges;"run.sh[root@test01mariadb_dockerfile]#catrun.sh#!/bin/bashmysqld_safe创建镜像
[root@test01mariadb_dockerfile]#dockerbuild-tliuxin/centos-mariadb:v1./创建容器
[root@test01mariadb_dockerfile]#dockerrun-d-p13306:3306liuxin/centos-mariadb:v1/root/run.sh[root@test01mariadb_dockerfile]#dockerpsCONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES7743527ac603liuxin/centos-mariadb:v1"/root/run.sh"5secondsagoUp3seconds0.0.0.0:13306->3306/tcpnostalgic_mirzakhani登录验证
[root@test01mariadb_dockerfile]#mysql-uroot-h127.0.0.1--port=13306-pEnterpassword:WelcometotheMariaDBmonitor.Commandsendwith;or\g.YourMariaDBconnectionidis1Serverversion:5.5.56-MariaDBMariaDBServerCopyright(c)2000,2017,Oracle,MariaDBCorporationAbandothers.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.MariaDB[(none)]>exit
以上就是关于“Docker如何创建MariaDB镜像”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注亿速云行业资讯频道。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。