修改 docker 容器(container) 里文件

以mysql为例

 

修改MySQL配置文件有两种方法:

  • 一是进入容器,修改容器里的MySQL的配置文件,然后重新启动容器,例如:

    $ sudo docker exec -it pwc-mysql /usr/bin/bash

    然后可以进入容器的命令行模式,接着修改 /etc/mysql/my.cnf 文件即可

  • 二是挂载主机的mysql配置文件,官方文档如下:

    The MySQL startup configuration is specified in the file /etc/mysql/my.cnf, and that file in turn includes any files found in the /etc/mysql/conf.d directory that end with .cnf. Settings in files in this directory will augment and/or override settings in /etc/mysql/my.cnf. If you want to use a customized MySQL configuration, you can create your alternative configuration file in a directory on the host machine and then mount that directory location as /etc/mysql/conf.d inside the mysql container.

    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.

你可能感兴趣的:(docker,修改docker文件,docker文件,docker,修改容器文件)