gogoWebsite

How to change the configuration file for running containers in Docker

Updated to 17 days ago

Referring to some methods online, some are either too troublesome or some are not successful.

The first method is to install Vim in Docker. First, exec enters your container and install it (because the container is isolated, Vim in Linux cannot be used, you have to enter the target container for installation). Just find the file and modify it according to the original directory, but I can't install it, no matter how you use it.apt-get updateandapt-get install -y vim,stillyum -y install vimNone of them work (which one may depend on your system, I'm not sure, most of the onlineapt-get, but I tried bothapt-get: command not foundyum: command not found), some even said they wanted to change the configuration, which was very troublesome, so I won’t try it anymore.

The second method is to usedocker inspaet [Container ID], I will find that there is a directory containing the container ID, which is the absolute address of the container. I copied it directly and returned to Linux to find it, but I did not succeed and did not find the etc directory I wanted. The first and second methods come from this articleBlog

There are also some methods that seem very troublesome and advanced, so I won’t try them anymore.


I think the following method is the easiest, the original text is fromZhihu, I successfully changed the configuration file after trying.
The steps are as follows. First, copy the file you want to modify. If you copy it, it will be very easy to modify. Either modify it directly or use a visual directory like Xftp to take the target file to Windows and then revise it. Then overwrite the old file with the new file.

docker cp [Container id]:Configuration file path in docker container Host pathdocker cpe4b322a429d1:/etc/grafana/ /home/

 // After the modificationdocker cpHost file path[Container id]:Configuration file path in docker containerdocker cp /home/ e4b322a429d1:/etc/grafana/