howto append/modify files in docker container from 'docker run … [command]'
I want to modify conf files in a docker image, however, I don’t want to re-build the docker image, instead, I want to do this thru the “docker run …. COMMAND”. I will put an “echo XXX >> /etc/XXX.conf” into the COMMAND. is this possible?
for example, I want to start a redis sentinel cluster, which includes at least 2 redis-server and 1 redis-sentinel. The second redis-server container need state “slaveof” in the redis.conf.
I do this in the following steps:
start redis-server with port 6479
docker run -d -p 6479:6379 docker.io/redis
start slave redis-server with 6579 by using same docker images, and state it’s a slave in the conf file:
docker run -d -p 6579:6379 docker.io/redis "/bin/echo 'slaveof 192.168.1.149 6479' >> /etc/redis.conf && redis-server /etc/redis.conf"
Here the COMMAND for ‘docker run’ is:
“/bin/echo ‘slaveof 192.168.1.149 6479’ >> /etc/redis.conf && redis-server /etc/redis.conf”
- Start sentinel, this is another docker images.
However, I stopped at the 2nd step. It returned error message like this:
/entrypoint.sh: line 10: /bin/echo ‘slaveof 192.168.1.149 6479’ >>
/etc/redis.conf && redis-server /etc/redis.conf: No such file or
So, how can I inject or modify conf file thru ‘docker run’ clause?
One Solution collect form web for “howto append/modify files in docker container from 'docker run … [command]'”
First launch your container giving it some name which you will need later (its easier than looking up container-id)
docker run --name container-name -d -p 6479:6379 docker.io/redis docker run --name aaaaa -d -p 6479:6379 docker.io/redis
If you need to login to a running container issue
docker exec -ti aaaaa /bin/bash
which will give you an interactive shell session inside the container where you can issue commands at will … If you just want to issue a command inside a running container without the interactive aspect issue
docker exec -ti aaaaa /some/command
where that /some/command will be executed inside the container … so something like this in your case
docker exec -ti aaaaa "/bin/echo 'slaveof 192.168.1.149 6479' >> /etc/redis.conf && redis-server /etc/redis.conf"