gpt4 book ai didi

Docker:构建镜像时编辑my.cnf

转载 作者:行者123 更新时间:2023-12-02 19:21:53 26 4
gpt4 key购买 nike

我对 docker 还很陌生。我想知道是否有办法为 docker 图像“硬编码”my.cnf 设置,而不是编辑 docker 容器。

我需要将这两行添加到 my.cnf 中才能使我的应用正常运行:

[client]
protocol=tcp

目前,我构建镜像运行容器并通过进入/etc/mysql/my.cnf 手动编辑它。谢谢。

最佳答案

您可以在构建时复制

FROM mysql
COPY my_custom.cnf /etc/mysql/my.cnf

或者另一种方法是更改​​配置文件并在运行时挂载配置文件,这样您就不需要重建或维护自定义镜像。

docker run --name some-mysql -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql

使用自定义 MySQL 配置文件

The default configuration for MySQL can be found in /etc/mysql/my.cnf, which may !includedir additional directories such as /etc/mysql/conf.d or /etc/mysql/mysql.conf.d. Please inspect the relevant files and directories within the mysql image itself for more details.

If /my/custom/config-file.cnf is the path and name of your custom configuration file, you can start your mysql container like this (note that only the directory path of the custom config file is used in this command):

 $ docker run --name some-mysql -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d
mysql:tag

This will start a new container some-mysql where the MySQL instance uses the combined startup settings from /etc/mysql/my.cnf and /etc/mysql/conf.d/config-file.cnf, with settings from the latter taking precedence.

https://hub.docker.com/_/mysql

更新:

仅对于 TCP,您不需要挂载您的配置,只需使用 --protocol 标志运行即可。

docker run --rm -it -e MYSQL_ALLOW_EMPTY_PASSWORD=test mysql:5.6.24 --protocol=TCP

关于Docker:构建镜像时编辑my.cnf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59048184/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com