栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

[docker]Docker安装MYSQL并挂载外部配置和数据

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

[docker]Docker安装MYSQL并挂载外部配置和数据

文章目录
  • 下载最新版mysql
  • 创建挂载目录
  • 创建my.cnf
  • 启动容器
    • 参数解释

下载最新版mysql
[root@iZwz9bpj7oo7xbzsrq86kmZ app]# docker pull mysql:latest
latest: Pulling from library/mysql
b380bbd43752: Pull complete 
f23cbf2ecc5d: Pull complete 
30cfc6c29c0a: Pull complete 
b38609286cbe: Pull complete 
8211d9e66cd6: Pull complete 
2313f9eeca4a: Pull complete 
7eb487d00da0: Pull complete 
4d7421c8152e: Pull complete 
77f3d8811a28: Pull complete 
cce755338cba: Pull complete 
69b753046b9f: Pull complete 
b2e64b0ab53c: Pull complete 
Digest: sha256:6d7d4524463fe6e2b893ffc2b89543c81dec7ef82fb2020a1b27606666464d87
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest
[root@iZwz9bpj7oo7xbzsrq86kmZ app]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               latest              ecac195d15af        3 weeks ago         516MB
创建挂载目录
[root@iZwz9bpj7oo7xbzsrq86kmZ mysql]# mkdir -p /app/mysql/conf
[root@iZwz9bpj7oo7xbzsrq86kmZ mysql]# mkdir -p /app/mysql/data
[root@iZwz9bpj7oo7xbzsrq86kmZ mysql]# mkdir -p /app/mysql/logs
创建my.cnf
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
 
[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
 
# Custom config should go here
!includedir /etc/mysql/conf.d/
启动容器
docker run --restart=always -d -v /app/mysql/conf/my.cnf:/etc/mysql/my.cnf -v /app/mysql/logs:/logs -v /app/mysql/data/mysql:/var/lib/mysql  -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:latest

查看当前容器的运行状态:

[root@iZwz9bpj7oo7xbzsrq86kmZ conf]# docker ps 
ConTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
fcbf1b231e5f        mysql:latest        "docker-entrypoint.s…"   48 seconds ago      Up 47 seconds       0.0.0.0:3306->3306/tcp, 33060/tcp   mysql
参数解释
--restart=always                                            -> 开机启动容器,容器异常自动重启
-d                                                          -> 以守护进程的方式启动容器
-v /app/mysql/conf/my.cnf:/etc/mysql/my.cnf          -> 映射配置文件
-v /app/mysql/logs:/logs                               -> 映射日志
-v /app/mysql/data/mysql:/var/lib/mysql                -> 映射数据
-p 3306:3306                                                -> 绑定宿主机端口
--name mysql                                                -> 指定容器名称
-e MYSQL_ROOT_PASSWORD=123456                               -> 写入配置root密码
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/513017.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号