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.

  • How to run JIRA and MySQL on same Docker Container
  • Run Jmeter from Jenkins with Docker
  • Permission denied for Dockerfile while using Custom Build Environment Plugin
  • docker run <IMAGE> <MULTIPLE COMMANDS>
  • Running testng suite on selenium grid and docker
  • Inconsistency in running docker-build on different environment
  • I do this in the following steps:

    1. start redis-server with port 6479

      docker run -d -p 6479:6379 docker.io/redis

    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 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”

    1. 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
    directory

    So, how can I inject or modify conf file thru ‘docker run’ clause?

  • How do I start a php server in the background as a daemon in a docker container
  • Permission denied in a Docker container even if user has the rights
  • build docker image with dockerfile by jenkins
  • Failed to connect docker url with PHP Unit
  • client (browser, jdbc driver) hangs when trying to connect with docker instance
  • Spotify docker maven build multiple images
  • 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"
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.