如何在正在运行的Docker容器中动态编辑文件 [英] How to edit a file dynamically in a running docker container

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

问题描述

背景

我已经构建了一个npm服务器(sinopia)docker映像(

I had build a npm server(sinopia) docker image(https://github.com/feuyeux/docker-atue/blob/master/docker-images/feuyeux_sinopia.md), and in the CMD line, it will run the start.sh every time when the container is generated.

CMD ["/opt/sinopia/start.sh"]

此shell将动态创建yaml文件.

This shell will create a yaml file dynamically.

sed -e 's/\#listen\: localhost/listen\: 0.0.0.0/' -e 's/allow_publish\: admin/allow_publish\: all/' /tmp/config.yaml > /opt/sinopia/config.yaml

问题

我希望我可以在容器运行时编辑此config.yaml,因为我希望按需更改内容.

I wish I could edit this config.yaml when the container is running, because I hope the content should be changed on demand.

查看快照照片

如上所示,第一行运行一个 sinopia 容器,在此容器中,有/opt/sinopia/config.yaml.但是我不知道如何获取此正在运行的容器以及如何编辑和检查此文件. 如果我作为 sinopia-ls 的一行,那么将运行一个新容器,而不是之前运行的容器.

As shown above, the first line runs a sinopia container, and in this container, there's /opt/sinopia/config.yaml. But I don't know how to obtain this running container and edit and check this file. If I did as the line of sinopia-ls, there's a new container runs instead of the before running one.

谢谢大家!

答案(详细信息,请参阅下面的内容)

sudo nsenter --target $PID --mount --uts --ipc --net --pid

root@58075317e47d:/# ls /opt/sinopia/
config.yaml  config_gen.js  start.sh  storage
root@58075317e47d:/# cat /opt/sinopia/config.yaml

推荐答案

对于docker 1.3,有一个新命令 docker exec .这使您可以输入正在运行的泊坞窗:

With docker 1.3, there is a new command docker exec. This allows you to enter a running docker:

docker exec -it <container-id> bash

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

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