How to edit a file dynamically in a running docker container

拟墨画扇 提交于 2019-12-04 14:09:06

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

You named your container, so you can find it using that name.

Then use nsenter (man nsenter) to send the command you want to do.

nsenter --target $$(docker inspect --format {{.State.Pid}} <container_name_or_ID>) --mount --uts --ipc --net --pid <cmd>

More info and solution on how to write inside of a running container : If you run SSHD in your Docker containers, you're doing it wrong!

Awan

you just need to mount the folder using -v as an option. i give an example

  1. let's say i have /home/awan/config.yml <--- this file is always dynamic must not put it inside container

  2. i run my container so i can mount that folder into my container

#sudo docker run -i -t -v /home/awan:/home/ubuntu/awan ubuntu/14.04 /bin/bash

  1. after that you just edit config.yml in your /home/awan/config.yml every changes that you applied automaticaly applied inside your docker container (/home/ubuntu/awan/config.yml) because you mount it
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!