How do I modify a startup script in a docker container when it is stopped?

We have a docker container which I run as:

docker run --name myname -e PROPERTY1=VALUE1   -d image/name 

Dockerfile used to build the container:

  • Give multiple tags to docker image using one docker tag command
  • Getting logs of tomcat containers running in kubernetes pods using fluentd, elsasticsearch and kibana
  • Error checking context is accessible: 'can't stat '.gvfs''. Please check permissions and try again
  • Docker for Windows and docker-maven-plugin - “SSLException: Unrecognized SSL message, plaintext connection” error
  • docker command is showing nothing in centos7
  • Why can't I `docker exec` after installing the official Django docker image?
  • ADD /
    CMD ["/bin/bash","/"]

    Can I edit the file without rebuilding the container.

    My guess is

    • stop the container
    • edit the file
    • start the container.

    How do I edit the file when the container is stopped?


  • Rancher OS: generate data in one container and set as environment variable in another container
  • Configure appveyor for Docker
  • Passive replicas with Docker swarm mode
  • How to attach to a demonized container in docker
  • Docker on Windows 10 startup: database tables and bound directories are disappearing
  • nodejs server cannot link Redis and MongoDB in the same Docker-Compose yml file
  • 2 Solutions collect form web for “How do I modify a startup script in a docker container when it is stopped?”

    You could follow the steps you outlined, but it requires knowing exactly where the container filesystem is on the host and making sure you have the right permissions to modify it. That’s not the path I’d suggest.

    Ideally you’d do everything through a Dockerfile so that you have a reproducible way to rebuild the image in the future. You’ll want that in six months when packages or dependencies need updating. You already know how to do that, so I’ll presume you’re looking for a quick hack.

    Quick Hack (Non-reproducible results)

    1. docker run your image to get it going as a container
    2. docker exec -it CONTAINER /bin/bash (or equivalent shell) to get into the running container. Edit your file within the container. Exit (ctrl-D typically).
      • This method of editing means you don’t have to find the container’s file system on the host or negotiate permissions to edit files there. You’re already in and on the file system.
      • But the only copy of the modified file is inside your container, so nobody else can reproduce what you did exactly.
    3. docker commit CONTAINER REPOSITORY:TAG
    4. docker run REPOSITORY:TAG

    If you modify the script you should rebuild the image. Rebuilding the image will be much faster than the first time because docker is capable to detect the modifications and rebuild only the necessary part.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.