如何在 Windows 10 上挂载 Docker MySQL Data/Socket 卷?

How to mount Docker MySQL Data/Socket volume on Windows 10?

我正在尝试 运行 docker mysql 上 windows 10 上的最新图像,并安装了主机上的数据目录。

我运行宁

docker run --rm --name=mysql --mount type=bind,src="C:\Docker Projects\mysql\mysql_data",dst=/var/lib/mysql mysql/mysql-server  

但它抱怨套接字不存在。

2020-01-20T17:23:22.758269Z 0 [ERROR] [MY-010270] [Server] Can't start server : Bind on unix socket: Operation not permitted
2020-01-20T17:23:22.758416Z 0 [ERROR] [MY-010258] [Server] Do you already have another mysqld server running on socket: /var/lib/mysql/mysql.sock ?

我可以看到 mysql mysql.sock.lock 已创建。我还尝试从主机创建一个 mysql.sock 文件。

我想这是在告诉我,我需要为 windows https://dev.mysql.com/doc/refman/5.7/en/deploy-mysql-nonlinux-docker.html 指定套接字文件的位置,但我似乎无法正确理解命令语法?

你是对的。问题是 mysql.sock 文件被放入 /var/lib/mysql,它被挂载到不支持 Unix 域套接字的 Windows 主机系统目录。

启动服务器时只需使用开关 --socket=/tmp/mysql.sock

如果您需要它来为 docker-compose 工作,您可以使用以下 docker-compose.ymlmy.cnf 文件。

在 my.cnf 文件中,套接字位置从 socket=/var/lib/mysql/mysql.sock 更改为 socket=/tmp/mysql.sock

docker-compose.yml

version: "3.7"
services:
  mysql:
    image: mysql/mysql-server:5.7.27
    volumes:
      - "./my.cnf:/etc/my.cnf"

my.cnf

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
skip-host-cache
skip-name-resolve
datadir=/var/lib/mysql
socket=/tmp/mysql.sock
secure-file-priv=/var/lib/mysql-files
user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid