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.

  • not able to perform gcloud init inside dockerfile
  • Install later version of docker-engine stuck on Travis build
  • Docker exposed port unreachable
  • docker after run image 404. Tomcat - requested resource is not available
  • Redirect traffic from docker container into localhost
  • How can you push using git to a Docker Cloud Repo?
  • I do this in the following steps:

    1. start redis-server with port 6479

      docker run -d -p 6479:6379

    2. 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 "/bin/echo 'slaveof 6479' >> /etc/redis.conf && redis-server /etc/redis.conf"

    Here the COMMAND for ‘docker run’ is:
    “/bin/echo ‘slaveof 6479’ >> /etc/redis.conf && redis-server /etc/redis.conf”

    1. Start sentinel, this is another docker images.

    However, I stopped at the 2nd step. It returned error message like this:

    / line 10: /bin/echo ‘slaveof 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?

  • Docker copy on write with big files
  • How can I force cancel dockerbuild using bash a command?
  • connect mysql client container to mysql server container Docker
  • Return 400 when i use kubernetes Deployment rollback API
  • Run a shell script on dokku app deployment
  • Base image for java
  • 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 run --name aaaaa          -d -p 6479:6379

    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 6479' >> /etc/redis.conf && redis-server /etc/redis.conf"
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.