Docker:在构建映像时编辑my.cnf [英] Docker: editing my.cnf in when building the image

查看:81
本文介绍了Docker:在构建映像时编辑my.cnf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对docker很陌生.我想知道是否有一种方法可以硬编码" docker映像的my.cnf设置,而不是编辑docker容器.

I am fairly new with docker. I wonder if there is a way how to "hardcode" my.cnf settings for docker image, instead of editing the docker container.

我需要将这两行添加到my.cnf中,以使我的应用正常工作:

I need to add these two lines into my.cnf for my app to work:

[client]
protocol=tcp

当前,我通过运行容器&通过进入/etc/mysql/my.cnf手动编辑它.谢谢.

Currently, I build the image run the container & edit it manually by going into /etc/mysql/my.cnf. Thanks.

推荐答案

您可以在构建时进行复制

You can copy at build time

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

或另一种方法是更改​​配置文件并在运行时挂载配置文件,因此您无需重建或维护自定义映像.

or another way is to change the config file and mount the config file at run time so you will not need to rebuild or maintain a custom image.

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

使用自定义MySQL配置文件

MySQL的默认配置可以在以下位置找到/etc/mysql/my.cnf ,可能!includedir附加目录,例如作为/etc/mysql/conf.d /etc/mysql/mysql.conf.d .请检查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.

如果/my/custom/config-file.cnf 是自定义文件的路径和名称配置文件,您可以像这样启动mysql容器(注意在此仅使用自定义配置文件的目录路径命令):

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 

这将启动一个新的容器some-mysql,其中MySQL实例使用来自以下位置的组合启动设置/etc/mysql/my.cnf /etc/mysql/conf.d/config-file.cnf 后者的设置优先.

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

更新:

仅对于TCP,您无需挂载配置,只需使用-protocol 标志运行即可.

For TCP only, you do not need to mount your config, just run with --protocol flag.

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

这篇关于Docker:在构建映像时编辑my.cnf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆