建立并运行docker mariadb镜像

1. 查找最新适合自己的mariadb镜像

[root@localhost ~]docker search mariadb
INDEX       NAME                                                                DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/mariadb                                                   MariaDB is a community-developed fork of M...   1744      [OK]       
docker.io   docker.io/bitnami/mariadb                                           Bitnami MariaDB Docker Image                    50                   [OK]
docker.io   docker.io/toughiq/mariadb-cluster                                   Dockerized Automated MariaDB Galera Cluste...   29                   [OK]
docker.io   docker.io/linuxserver/mariadb                                       A Mariadb container, brought to you by Lin...   23                   
docker.io   docker.io/million12/mariadb                                         MariaDB 10 on CentOS-7 with UTF8 defaults       14                   [OK]
docker.io   docker.io/colinmollenhour/mariadb-galera-swarm                      MariaDb w/ Galera Cluster, DNS-based servi...   13                   [OK]
docker.io   docker.io/panubo/mariadb-galera                                     MariaDB Galera Cluster                          13                   [OK]
docker.io   docker.io/webhippie/mariadb                                         Docker images for mariadb                       13                   [OK]
docker.io   docker.io/yobasystems/alpine-mariadb                                MariaDB running on Alpine Linux [docker]        12                   [OK]
docker.io   docker.io/diegomarangoni/mariadb-galera                             Creates a MariaDB Galera Cluster                10                   [OK]
docker.io   docker.io/jsurf/rpi-mariadb                                         mariadb for rpi based on jsurf/rpi-raspbian     9                    [OK]
docker.io   docker.io/monitoringartist/zabbix-db-mariadb                        Docker image of MariaDB optimized for Zabbix    9                    [OK]
#挑选STARS最高的吧
[root@localhost~] docker pull docker.io/mariadb:latest
2. 配置数据库文件路径

# 创建本地数据库文件路径
[root@localhost~]mkdir -p /data/mysql
#修改对象(文件)的安全上下文。比如:用户:角色:类型:安全级别
[root@localhost~]chcon -Rt svirt_sandbox_file_t /data/mysql
3. 启动镜像(设置为自启动)

[root@localhost~]docker run -p 3306:3306 -v /data/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=hello123 --name mariadb -d --restart unless-stopped docker.io/mariadb:latest 

4. 设置mariadb自动启动

#安装完成MariaDB,首先启动MariaDB
[root@localhost~]systemctl start mariadb
#设置开机启动
[root@localhost~]systemctl enable mariadb
5. 设置相关账号

#首次使用设置root账号
[root@xxxx~]mysql_secure_installation
#登录mysql,设置远程登录账号
[root@xxxx~]mysql -uroot -p
mysql> grant all privileges on *.* to remoteroot@'%' identified by 'hello1234';
mysql>privilege flush
#OK,后续可以使用remoteroot登录数据库了。






你可能感兴趣的:(部署)