Docker:在构建映像时编辑my.cnf

编程入门 行业动态 更新时间:2024-10-11 19:16:13
本文介绍了Docker:在构建映像时编辑myf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

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

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

[client] protocol=tcp

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

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

推荐答案

您可以在构建时进行复制

You can copy at build time

FROM mysql COPY my_customf /etc/mysql/myf

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

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/myf ,可能!includedir附加目录,例如作为/etc/mysql/conf.d 或/etc/mysql/mysql.conf.d .请检查mysql映像本身中的相关文件和目录,用于更多细节.

The default configuration for MySQL can be found in /etc/mysql/myf, 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-filef 是自定义文件的路径和名称配置文件,您可以像这样启动mysql容器(注意在此仅使用自定义配置文件的目录路径命令):

If /my/custom/config-filef 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/myf 和/etc/mysql/conf.d/config-filef 后者的设置优先.

hub.docker/_/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

本文发布于:2023-10-27 04:28:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1532317.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:映像   编辑   Docker   cnf

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!