当前位置: 首页 > news >正文

Windows VMWare Centos环境下安装Docker并配置MySql

虚拟机安装

官网下载Centos Stream 10系统镜像

安装了Minimal版,Terminal中粘贴、复制指令不方便,又新建了虚拟机,安装GUI版

终端输入指令报错修复

   输入指令报错:failed to set locale defaulting to C.UTF-8,安装语言包

# 查看语言包
$ locale -a# 安装英文语言包
$ sudo dnf install glibc-langpack-en

安装Docker 

#使用YUM包管理器
sudo yum update
sudo dnf -y install yum-utils#安装 dnf-plugins-core包(提供管理 DNF 仓库的命令)
sudo dnf -y install dnf-plugins-core#设置镜像sudo yum-config-manager --add-repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo#安装最新版本的 Docker-CE 和 containerd 执行如下命令
sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin#安装完成后启动docker服务
sudo systemctl start docker#检查docker是否正常运行
sudo systemctl status docker#设置docker自动启动
sudo systemctl enable docker

 检查网络联通

  VMWare 中Centos的网络信息:

 

 windows宿主机,ping 虚拟机:

Docker 安装Mysql

 初次拉取报错Error response from daemon。

duel@localhost:~$ docker pull mysql:5.7.25
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.51/images/create?fromImage=docker.io%2Flibrary%2Fmysql&tag=5.7.25": dial unix /var/run/docker.sock: connect: permission denied
duel@localhost:~$ sudo docker pull mysql:5.7.25
Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

解决方法:通过vim在daemon.json中添加镜像加速。

sudo vim /etc/docker/daemon.json
{"registry-mirrors": ["https://docker.hpcloud.cloud","https://docker.m.daocloud.io","https://docker.unsee.tech","https://docker.1panel.live","http://mirrors.ustc.edu.cn","https://docker.chenby.cn","http://mirror.azure.cn","https://dockerpull.org","https://dockerhub.icu","https://hub.rat.dev"]
}

vim编辑保存后,重启docker,并再次尝试拉取MySql: 

sudo systemctl daemon-reload
sudo systemctl restart docker
sudo systemctl status docker
sudo docker pull mysql:5.7.25

拉取MySql成功后,创建文件夹做挂载

$ sudo mkdir /mydata/mysql/conf
$ sudo mkdir /mydata/mysql/data
$ sudo mkdir /mydata/mysql/conf

创建my.cnf配置文件,并在vim中添加内容

#创建my.cnf配置文件
sudo touch /mydata/mysql/conf/my.cnf#vim中打开
sudo vim  /mydata/mysql/conf/my.cnf

vim中添加的内容如下:

[mysqld]
user=mysql
character-set-server=utf8
default_authentication_plugin=mysql_native_password
secure_file_priv=/var/lib/mysql
expire_logs_days=7
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
max_connections=1000[client]
default-character-set=utf8[mysql]
default-character-set=utf8

创建并运行

# sudo docker run --restart=always --privileged=true -p 3306:3306 --name mysql -v /mydata/mysql/log:/var/log/mysql -v /mydata/mysql/data:/var/lib/mysql -v /mydata/mysql/conf/my.cnf:/etc/mysql/my.cnf -v /mydata/mysql/conf/conf.d:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=pwd123456 -d mysql:5.7.25sudo docker run --restart=always --privileged=true -p 3306:3306 --name mysql 
-v /mydata/mysql/log:/var/log/mysql 
-v /mydata/mysql/data:/var/lib/mysql 
-v /mydata/mysql/conf/my.cnf:/etc/mysql/my.cnf 
-v /mydata/mysql/conf/conf.d:/etc/mysql/conf.d 
-e MYSQL_ROOT_PASSWORD=pwd123456 
-d mysql:5.7.25

 参数说明

​ --restart=always: 当Docker 重启时,容器会自动启动。

​ --privileged=true:容器内的root拥有真正root权限,否则容器内root只是外部普通用户权限

​ -p 3306:3306:将容器的3306端口映射到主机的3306端口

​ -v /mydata/mysql/conf:/etc/mysql:将配置文件夹挂载到主机

​ -v /mydata/mysql/log:/var/log/mysql:将日志文件夹挂载到主机

​ -v /mydata/mysql/data:/var/lib/mysql:将配置文件夹挂载到主机

​ -v /mydata/mysql/conf/my.cnf:/etc/mysql/my.cnf:映射配置文件

​ -v /mydata/mysql/conf/conf.d:/etc/mysql/conf.d:映射配置文件

​ -e MYSQL_ROOT_PASSWORD=pwd123456:初始化root用户的密码

​ -d mysql:5.7.25 以后台方式启动

#进入容器
sudo docker exec -it mysql bash
root@96f90204aefb:/# mysql -u root -p
Enter password: pwd123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25 MySQL Community Server (GPL)Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql> select user,host from user;
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| root          | %         |
| mysql.session | localhost |
| mysql.sys     | localhost |
| root          | localhost |
+---------------+-----------+
4 rows in set (0.00 sec)

 windows宿主机中使用Navicat测试连接:

mysql> exit
Bye
root@96f90204aefb:/# exit
exit
duel@localhost:~$ sudo shutdown -h now

重启虚拟机后,查看Docker状态,测试MySql自启成功: 

duel@localhost:~$ sudo systemctl status dockerduel@localhost:~$ sudo docker exec -it mysql bash
root@96f90204aefb:/# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.25 MySQL Community Server (GPL)Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> 

http://www.lryc.cn/news/576183.html

相关文章:

  • 香港 8C 站群服务器买来可以做哪些业务?
  • opi是opensuse独占的吗?
  • 工厂“智能指挥家”上线,富唯智能调度系统让机器人高效协作
  • 关于SAP产品名称变更通知 SAP云认证实施商工博科技
  • 导出docker-compse.yml中docker镜像成tar文件
  • 基于fpga的串口控制的音乐播放器
  • 从0开始学习计算机视觉--Day04--损失函数
  • 微信小程序:实现树形结构组件
  • 【MySQL进阶】服务器配置与管理——系统变量,选项,状态变量
  • 将ONNX模型转换为(OPENMV可用的格式)TensorFlow Lite格式
  • Flotherm许可状态检查
  • Godot4.3类星露谷游戏开发之【简易库存】(UI部分)
  • HTTPS hostname wrong: should be <xxx>错误解决
  • 【大模型水印论文阅读2】前缀文本编码、均匀性约束
  • Stable Diffusion 3终极提示词库:2000个工业设计场景生成公式(2025企业级实战指南)
  • 强化学习理论基础:从Q-learning到PPO的算法演进(2)
  • openGL学习(基本窗口)
  • [ linux-系统 ] 磁盘与文件系统
  • 【论文阅读 | CVPR 2025 |MambaVision:一种混合 Mamba-Transformer 视觉骨干网络】
  • 2025.6.27总结
  • 机器人 URDF学习笔记
  • Windows 10 ARM64平台CAN程序开发
  • 飞凌A40i使用笔记
  • React中的ErrorBoundary
  • 【Yonghong 企业日常问题08 】永洪BI的Apache Tomcat版本升级指南
  • 【CV数据集介绍-40】Cityscapes 数据集:助力自动驾驶的语义分割神器
  • 攻防世界-MISC-Cephalopod
  • gemini-cli 踩坑实录
  • ARM64 linux系统的一般执行过程
  • C++ 函数特性详解:默认参数、重载、引用与指针区别