欢迎投稿

今日深度:

Mariadb docker 安装,mariadbdocker安装

Mariadb docker 安装,mariadbdocker安装


常用执行方式:
1.指定本地配置
2. 指定本地database存放路径,便于其他客户端或程序管理
docker run –name at-mariadb -v /usr/local/share/mariadb/custom_conf:/etc/mysql/conf.d -v /usr/local/share/mariadb/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=banrieen -d mariadb:latest
How to use this image
Start a mariadb server instance
Starting a MariaDB instance is simple:

最简单的执行方式,需要设置root登陆密码

$ docker run –name some-mariadb -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb:tag
… where some-mariadb is the name you want to assign to your container, my-secret-pw is the password to be set for the MySQL root user and tag is the tag specifying the MySQL version you want. See the list above for relevant tags.
Connect to MySQL from an application in another Docker container
Since MariaDB is intended as a drop-in replacement for MySQL, it can be used with many applications. This image exposes the standard MySQL port (3306), so container linking makes the MySQL instance available to other application containers. Start your application container like this in order to link it to the MySQL container:

在其他contian中连接mariadb的方法
dockerrunnamesomeapplinksomemariadb:mysqldapplicationthatusesmysqlConnecttoMariaDBfromtheMySQLcommandlineclientThefollowingcommandstartsanothermariadbcontainerinstanceandrunsthemysqlcommandlineclientagainstyouroriginalmariadbcontainer,allowingyoutoexecuteSQLstatementsagainstyourdatabaseinstance:" role="presentation">dockerrunnamesome?applinksome?mariadb:mysql?dapplication?that?uses?mysqlConnecttoMariaDBfromtheMySQLcommandlineclientThefollowingcommandstartsanothermariadbcontainerinstanceandrunsthemysqlcommandlineclientagainstyouroriginalmariadbcontainer,allowingyoutoexecuteSQLstatementsagainstyourdatabaseinstance: docker run -it --link some-mariadb:mysql --rm mariadb sh -c 'exec mysql -h"MYSQLPORT3306TCPADDRP" role="presentation">MYSQLPORT3306TCPADDR?PMYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD”’

指定Contains 的network方式为host,其他应用可以通过host ip 和端口访问该contains

docker run –network=’host’ –name at-mariadb -v /usr/local/share/mariadb/custom_conf:/etc/mysql/conf.d -v /usr/local/share/mariadb/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=banrieen -d mariadb:latest
… where some-mariadb is the name of your original mariadb container.
This image can also be used as a client for non-Docker or remote MariaDB instances:
dockerrunitrmmariadbmysqlhsome.mysql.hostusomemysqluserpMoreinformationabouttheMySQLcommandlineclientcanbefoundintheMySQLdocumentationContainershellaccessandviewingMySQLlogsThedockerexeccommandallowsyoutoruncommandsinsideaDockercontainer.Thefollowingcommandlinewillgiveyouabashshellinsideyourmariadbcontainer:" role="presentation">dockerrun?itrmmariadbmysql?hsome.mysql.host?usome?mysql?user?pMoreinformationabouttheMySQLcommandlineclientcanbefoundintheMySQLdocumentationContainershellaccessandviewingMySQLlogsThedockerexeccommandallowsyoutoruncommandsinsideaDockercontainer.Thefollowingcommandlinewillgiveyouabashshellinsideyourmariadbcontainer: docker exec -it some-mariadb bash
The MariaDB Server log is available through Docker’s container log:
dockerlogssomemariadbUsingacustomMySQLconfigurationfileTheMariaDBstartupconfigurationisspecifiedinthefile/etc/mysql/my.cnf,andthatfileinturnincludesanyfilesfoundinthe/etc/mysql/conf.ddirectorythatendwith.cnf.Settingsinfilesinthisdirectorywillaugmentand/oroverridesettingsin/etc/mysql/my.cnf.IfyouwanttouseacustomizedMySQLconfiguration,youcancreateyouralternativeconfigurationfileinadirectoryonthehostmachineandthenmountthatdirectorylocationas/etc/mysql/conf.dinsidethemariadbcontainer.If/my/custom/configfile.cnfisthepathandnameofyourcustomconfigurationfile,youcanstartyourmariadbcontainerlikethis(notethatonlythedirectorypathofthecustomconfigfileisusedinthiscommand):" role="presentation">dockerlogssome?mariadbUsingacustomMySQLconfigurationfileTheMariaDBstartupconfigurationisspecifiedinthefile/etc/mysql/my.cnf,andthatfileinturnincludesanyfilesfoundinthe/etc/mysql/conf.ddirectorythatendwith.cnf.Settingsinfilesinthisdirectorywillaugmentand/oroverridesettingsin/etc/mysql/my.cnf.IfyouwanttouseacustomizedMySQLconfiguration,youcancreateyouralternativeconfigurationfileinadirectoryonthehostmachineandthenmountthatdirectorylocationas/etc/mysql/conf.dinsidethemariadbcontainer.If/my/custom/config?file.cnfisthepathandnameofyourcustomconfigurationfile,youcanstartyourmariadbcontainerlikethis(notethatonlythedirectorypathofthecustomconfigfileisusedinthiscommand): docker run –name some-mariadb -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb:tag
This will start a new container some-mariadb where the MariaDB instance uses the combined startup settings from /etc/mysql/my.cnf and /etc/mysql/conf.d/config-file.cnf , with settings from the latter taking precedence.
Note that users on host systems with SELinux enabled may see issues with this. The current workaround is to assign the relevant SELinux policy type to your new config file so that the container will be allowed to mount it:
chconRtsvirtsandboxfilet/my/customConfigurationwithoutacnffileManyconfigurationoptionscanbepassedasflagstomysqld.Thiswillgiveyoutheflexibilitytocustomizethecontainerwithoutneedingacnffile.Forexample,ifyouwanttochangethedefaultencodingandcollationforalltablestouseUTF8(utf8mb4)justrunthefollowing:" role="presentation">chcon?Rtsvirtsandboxfilet/my/customConfigurationwithoutacnffileManyconfigurationoptionscanbepassedasflagstomysqld.Thiswillgiveyoutheflexibilitytocustomizethecontainerwithoutneedingacnffile.Forexample,ifyouwanttochangethedefaultencodingandcollationforalltablestouseUTF?8(utf8mb4)justrunthefollowing: docker run –name some-mariadb -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb:tag –character-set-server=utf8mb4 –collation-server=utf8mb4_unicode_ci
If you would like to see a complete list of available options, just run:
dockerrunitrmmariadb:tagverbosehelpEnvironmentVariablesWhenyoustartthemariadbimage,youcanadjusttheconfigurationoftheMariaDBinstancebypassingoneormoreenvironmentvariablesonthedockerruncommandline.Donotethatnoneofthevariablesbelowwillhaveanyeffectifyoustartthecontainerwithadatadirectorythatalreadycontainsadatabase:anypreexistingdatabasewillalwaysbeleftuntouchedoncontainerstartup.MYSQLROOTPASSWORDThisvariableismandatoryandspecifiesthepasswordthatwillbesetfortheMariaDBrootsuperuseraccount.Intheaboveexample,itwassettomysecretpw.MYSQLDATABASEThisvariableisoptionalandallowsyoutospecifythenameofadatabasetobecreatedonimagestartup.Ifauser/passwordwassupplied(seebelow)thenthatuserwillbegrantedsuperuseraccess(correspondingtoGRANTALL)tothisdatabase.MYSQLUSER,MYSQLPASSWORDThesevariablesareoptional,usedinconjunctiontocreateanewuserandtosetthatuserspassword.Thisuserwillbegrantedsuperuserpermissions(seeabove)forthedatabasespecifiedbytheMYSQLDATABASEvariable.Bothvariablesarerequiredforausertobecreated.Donotethatthereisnoneedtousethismechanismtocreatetherootsuperuser,thatusergetscreatedbydefaultwiththepasswordspecifiedbytheMYSQLROOTPASSWORDvariable.MYSQLALLOWEMPTYPASSWORDThisisanoptionalvariable.Settoyestoallowthecontainertobestartedwithablankpasswordfortherootuser.NOTE:Settingthisvariabletoyesisnotrecommendedunlessyoureallyknowwhatyouaredoing,sincethiswillleaveyourMariaDBinstancecompletelyunprotected,allowinganyonetogaincompletesuperuseraccess.MYSQLRANDOMROOTPASSWORDThisisanoptionalvariable.Settoyestogeneratearandominitialpasswordfortherootuser(usingpwgen).Thegeneratedrootpasswordwillbeprintedtostdout(GENERATEDROOTPASSWORD:..).InitializingafreshinstanceWhenacontainerisstartedforthefirsttime,anewdatabasewiththespecifiednamewillbecreatedandinitializedwiththeprovidedconfigurationvariables.Furthermore,itwillexecutefileswithextensions.sh,.sqland.sql.gzthatarefoundin/dockerentrypointinitdb.d.Fileswillbeexecutedinalphabeticalorder.YoucaneasilypopulateyourmariadbservicesbymountingaSQLdumpintothatdirectoryandprovidecustomimageswithcontributeddata.SQLfileswillbeimportedbydefaulttothedatabasespecifiedbytheMYSQLDATABASEvariable.CaveatsWheretoStoreDataImportantnote:ThereareseveralwaystostoredatausedbyapplicationsthatruninDockercontainers.Weencourageusersofthemariadbimagestofamiliarizethemselveswiththeoptionsavailable,including:LetDockermanagethestorageofyourdatabasedatabywritingthedatabasefilestodiskonthehostsystemusingitsowninternalvolumemanagement.Thisisthedefaultandiseasyandfairlytransparenttotheuser.Thedownsideisthatthefilesmaybehardtolocatefortoolsandapplicationsthatrundirectlyonthehostsystem,i.e.outsidecontainers.Createadatadirectoryonthehostsystem(outsidethecontainer)andmountthistoadirectoryvisiblefrominsidethecontainer.Thisplacesthedatabasefilesinaknownlocationonthehostsystem,andmakesiteasyfortoolsandapplicationsonthehostsystemtoaccessthefiles.Thedownsideisthattheuserneedstomakesurethatthedirectoryexists,andthate.g.directorypermissionsandothersecuritymechanismsonthehostsystemaresetupcorrectly.TheDockerdocumentationisagoodstartingpointforunderstandingthedifferentstorageoptionsandvariations,andtherearemultipleblogsandforumpostingsthatdiscussandgiveadviceinthisarea.Wewillsimplyshowthebasicprocedurehereforthelatteroptionabove:Createadatadirectoryonasuitablevolumeonyourhostsystem,e.g./my/own/datadir.Startyourmariadbcontainerlikethis:" role="presentation">dockerrun?itrmmariadb:tagverbosehelpEnvironmentVariablesWhenyoustartthemariadbimage,youcanadjusttheconfigurationoftheMariaDBinstancebypassingoneormoreenvironmentvariablesonthedockerruncommandline.Donotethatnoneofthevariablesbelowwillhaveanyeffectifyoustartthecontainerwithadatadirectorythatalreadycontainsadatabase:anypre?existingdatabasewillalwaysbeleftuntouchedoncontainerstartup.MYSQLROOTPASSWORDThisvariableismandatoryandspecifiesthepasswordthatwillbesetfortheMariaDBrootsuperuseraccount.Intheaboveexample,itwassettomy?secret?pw.MYSQLDATABASEThisvariableisoptionalandallowsyoutospecifythenameofadatabasetobecreatedonimagestartup.Ifauser/passwordwassupplied(seebelow)thenthatuserwillbegrantedsuperuseraccess(correspondingtoGRANTALL)tothisdatabase.MYSQLUSER,MYSQLPASSWORDThesevariablesareoptional,usedinconjunctiontocreateanewuserandtosetthatuserspassword.Thisuserwillbegrantedsuperuserpermissions(seeabove)forthedatabasespecifiedbytheMYSQLDATABASEvariable.Bothvariablesarerequiredforausertobecreated.Donotethatthereisnoneedtousethismechanismtocreatetherootsuperuser,thatusergetscreatedbydefaultwiththepasswordspecifiedbytheMYSQLROOTPASSWORDvariable.MYSQLALLOWEMPTYPASSWORDThisisanoptionalvariable.Settoyestoallowthecontainertobestartedwithablankpasswordfortherootuser.NOTE:Settingthisvariabletoyesisnotrecommendedunlessyoureallyknowwhatyouaredoing,sincethiswillleaveyourMariaDBinstancecompletelyunprotected,allowinganyonetogaincompletesuperuseraccess.MYSQLRANDOMROOTPASSWORDThisisanoptionalvariable.Settoyestogeneratearandominitialpasswordfortherootuser(usingpwgen).Thegeneratedrootpasswordwillbeprintedtostdout(GENERATEDROOTPASSWORD:..).InitializingafreshinstanceWhenacontainerisstartedforthefirsttime,anewdatabasewiththespecifiednamewillbecreatedandinitializedwiththeprovidedconfigurationvariables.Furthermore,itwillexecutefileswithextensions.sh,.sqland.sql.gzthatarefoundin/docker?entrypoint?initdb.d.Fileswillbeexecutedinalphabeticalorder.YoucaneasilypopulateyourmariadbservicesbymountingaSQLdumpintothatdirectoryandprovidecustomimageswithcontributeddata.SQLfileswillbeimportedbydefaulttothedatabasespecifiedbytheMYSQLDATABASEvariable.CaveatsWheretoStoreDataImportantnote:ThereareseveralwaystostoredatausedbyapplicationsthatruninDockercontainers.Weencourageusersofthemariadbimagestofamiliarizethemselveswiththeoptionsavailable,including:LetDockermanagethestorageofyourdatabasedatabywritingthedatabasefilestodiskonthehostsystemusingitsowninternalvolumemanagement.Thisisthedefaultandiseasyandfairlytransparenttotheuser.Thedownsideisthatthefilesmaybehardtolocatefortoolsandapplicationsthatrundirectlyonthehostsystem,i.e.outsidecontainers.Createadatadirectoryonthehostsystem(outsidethecontainer)andmountthistoadirectoryvisiblefrominsidethecontainer.Thisplacesthedatabasefilesinaknownlocationonthehostsystem,andmakesiteasyfortoolsandapplicationsonthehostsystemtoaccessthefiles.Thedownsideisthattheuserneedstomakesurethatthedirectoryexists,andthate.g.directorypermissionsandothersecuritymechanismsonthehostsystemaresetupcorrectly.TheDockerdocumentationisagoodstartingpointforunderstandingthedifferentstorageoptionsandvariations,andtherearemultipleblogsandforumpostingsthatdiscussandgiveadviceinthisarea.Wewillsimplyshowthebasicprocedurehereforthelatteroptionabove:Createadatadirectoryonasuitablevolumeonyourhostsystem,e.g./my/own/datadir.Startyourmariadbcontainerlikethis: docker run –name some-mariadb -v /my/own/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb:tag
The -v /my/own/datadir:/var/lib/mysql part of the command mounts the /my/own/datadir directory from the underlying host system as /var/lib/mysql inside the container, where MySQL by default will write its data files.
Note that users on host systems with SELinux enabled may see issues with this. The current workaround is to assign the relevant SELinux policy type to the new data directory so that the container will be allowed to access it:
chconRtsvirtsandboxfilet/my/own/datadirNoconnectionsuntilMySQLinitcompletesIfthereisnodatabaseinitializedwhenthecontainerstarts,thenadefaultdatabasewillbecreated.Whilethisistheexpectedbehavior,thismeansthatitwillnotacceptincomingconnectionsuntilsuchinitializationcompletes.Thismaycauseissueswhenusingautomationtools,suchasdockercompose,whichstartseveralcontainerssimultaneously.UsageagainstanexistingdatabaseIfyoustartyourmariadbcontainerinstancewithadatadirectorythatalreadycontainsadatabase(specifically,amysqlsubdirectory),the" role="presentation">chcon?Rtsvirtsandboxfilet/my/own/datadirNoconnectionsuntilMySQLinitcompletesIfthereisnodatabaseinitializedwhenthecontainerstarts,thenadefaultdatabasewillbecreated.Whilethisistheexpectedbehavior,thismeansthatitwillnotacceptincomingconnectionsuntilsuchinitializationcompletes.Thismaycauseissueswhenusingautomationtools,suchasdocker?compose,whichstartseveralcontainerssimultaneously.UsageagainstanexistingdatabaseIfyoustartyourmariadbcontainerinstancewithadatadirectorythatalreadycontainsadatabase(specifically,amysqlsubdirectory),theMYSQL_ROOT_PASSWORD variable should be omitted from the run command line; it will in any case be ignored, and the pre-existing database will not be changed in any way.
Creating database dumps
Most of the normal tools will work, although their usage might be a little convoluted in some cases to ensure they have access to the mysqld server. A simple way to ensure this is to use docker exec and run the tool from the same container, similar to the following:
dockerexecsomemariadbshcexecmysqldumpalldatabasesurootp"" role="presentation">dockerexecsome?mariadbsh?cexecmysqldump??all?databases?uroot?p"MYSQL_ROOT_PASSWORD”’ > /some/path/on/your/host/all-databases.sql

www.htsjk.Com true http://www.htsjk.com/mariadb/35762.html NewsArticle Mariadb docker 安装,mariadbdocker安装 常用执行方式: 1.指定本地配置 2. 指定本地database存放路径,便于其他客户端或程序管理 docker run –name at-mariadb -v /usr/local/share/mariadb/custom_conf:/etc/mys...
相关文章
    暂无相关文章
评论暂时关闭