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.

  • Nginx with dockerized NodeJS
  • docker-compose up "ERROR: Error processing tar file(archive/tar: invalid tar header)
  • Multiple assemblies with equivalent identity have been imported: '<in-memory assembly>' and '<in-memory assembly>' [Solved]
  • PID mapping between docker and host
  • Accessing an Apache server in a Docker container using a hostname
  • How would I mount docker container filesystem?
  • 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?

  • Exposing ports to all containers, not only the host
  • Best way to use mysql for docker based microservices
  • How to run executable jar in docker
  • Localhost not working with Docker+Wordpress in MacOS
  • Unsupported config option for services service: 'httpd'
  • How to see the source of a DockerHub container so I can adapt it?
  • 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.