Docker Community Forums

Share and learn in the Docker community.

Edit file in container


(Tcpip) #1

Hi all,

I have a simple docker with ansible, and I need to edit files inside the container, how can I edit this files without getting inside the container?


(Kstieger) #2

there are several ways to do this.

I guess the most common way to do this, is to mount the file(s) you want edit later from the host filesystem into the docker instance when you ‘run’ the instance eg.
docker run -d --mount 'type=bind,src=/path/on/host/file.txt,dst=/path/in/container/file.txt' .
So you can edit the file on host and read or excute the data in the container.

An other way would be to copy the edited file from host and replacing the existing file in container eg.
docker cp /path/on/host/file.txt <containername>:/path/in/container/file.txt

It is also possible, but very dirty and I never would do that, do edit the file direclty in storage path somewhere in /var/lib/docker/ .

(Tcpip) #3

Hello kstieger,

I will check it and I will send an update.