Docker Community Forums

Share and learn in the Docker community.

How to update file content via docker exec


(Allenh) #1

I am trying to update a mounted file in the container via docker exec.
when I run the below:

root@nfvo1-E9000:/root# docker exec -ti 2a5df6777095 echo abc > /data/raft/peers.json
-bash: /data/raft/peers.json: No such file or directory

I realize the wrapped command may look for this file on the docker host, but actually it is mounted at somewhere else on the host, I then try put ‘’ around the command:

root@nfvo1-E9000:/root# docker exec -ti 2a5df6777095 'echo abc > /data/raft/peers.json’
Cannot run exec command f12b54e8605929bab1d4a2204d4ce739f29ca38d34e96c52fe7e3692fd3bc19c in container 2a5df6777095faa8f66a64ac8fd61191c66758da769eb81dda062a12600557df: [8] System error: exec: “echo abc > /data/raft/peers.json”: stat echo abc > /data/raft/peers.json: no such file or directory
Error starting exec command in container f12b54e8605929bab1d4a2204d4ce739f29ca38d34e96c52fe7e3692fd3bc19c: Cannot run exec command f12b54e8605929bab1d4a2204d4ce739f29ca38d34e96c52fe7e3692fd3bc19c in container 2a5df6777095faa8f66a64ac8fd61191c66758da769eb81dda062a12600557df: [8] System error: exec: “echo abc > /data/raft/peers.json”: stat echo abc > /data/raft/peers.json: no such file or directory

this time it still complains the file is not found, but I can use the vi in the command to edit this file:

docker exec -ti 2a5df6777095 vi /data/raft/peers.json

any idea?


(Allenh) #2

solution found: