docker安装mysql8.0并挂载到主机

1、docker pull mysql:8.0.20

2、cd /home

  mkdir mnt

  cd mnt

  mkdir mysql8.0.20

  cd mysql8.0.20

  mkdir logs mysql conf data mysql-files

3、vi mysql.sh

  

#!/bin/sh                                                                                    
 docker run \
 -p 3306:3306 \
 --name mysql8.0.20 \
# 挂载文件权限设置
 --privileged=true \
# docker重启时容器自动启动
 --restart always \
# 挂载配置文件
 -v /home/mnt/mysql8.0.20/conf/conf.d:/etc/mysql/conf.d \
 -v /home/mnt/mysql8.0.20/conf/my.cnf:/etc/mysql/my.cnf \
 -v /home/mnt/mysql8.0.20/mysql-files:/var/lib/mysql-files \ 
# 挂载日志
 -v /home/mnt/mysql8.0.20/logs:/logs \
# 挂载数据
 -v /home/mnt/mysql8.0.20/data:/var/lib/mysql \
# 容器时间与主机同步
 -v /etc/localtime:/etc/localtime    
 
-e MYSQL_ROOT_PASSWORD=密码 \
 
-d mysql:8.0.20
容器时间与宿主机同步3\

posted @ 2021-02-20 10:45  xing柠檬  阅读(219)  评论(0编辑  收藏  举报