在Docker容器中编辑文件 [英] Editing Files inside of a Docker Container

查看:281
本文介绍了在Docker容器中编辑文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编辑已下载到主机上的Docker容器内部的配置文件?

How can I edit the config files that are inside of a docker container that has been downloaded on the host?

我正在使用

I am using this tutorial but I am not sure where to find and edit the traefik.toml file

推荐答案

有多种方法可以实现:

您可以通过运行以下命令输入容器:

You can enter the container by running the command:

docker exec -it <container-name> bash

但是请注意,根据容器的不同,您可能没有简单的文本编辑器.

Note however depending on the container you may not have a simple text editor..

另一种选择是通过运行以下命令将要编辑的文件从容器复制到主机上

Another alternative would be to copy the file you want to edit from the container onto your host by running:

docker cp <container-name>:/path/to/file/in/container .

编辑文件,然后将其复制回容器:

Edit the file and then copy it back into the container:

docker cp <file> <container-name>:/path/to/file/in/container


第三种选择是创建绑定安装将文件从容器暴露到主机上


Third option is to create a bind mount which will effectively expose the file from the container onto the host

docker run -v $(pwd)/files:/dir/containing/file/in/container ...

这将在文件"目录中显示容器文件夹,并且您可以在主机中编辑文件,该文件将直接反映在容器内部.

This will expose the container folder in the "files" directory, and you can edit the file in the host and it will be directly reflected inside the container.

这篇关于在Docker容器中编辑文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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