Search code examples
dockereditconfiguration-files

How can I edit files in a docker container when it's down/not-started


Use-case: I started some nice docker image and my container needs some playing around (configuration file changes for research). I edit a file (using sed or vim ;-) ) and then I stop the container and try to start it. Now I made a mistake in the configuration and the docker container does not come up when I do: docker restart <my-container-id/-name> How can I edit the configuration-file to fix the mistake?


Solution

  • Based on the advice of jpetazzo (see https://github.com/jpetazzo/nsenter/issues/27#issuecomment-53799568) I started a different container that used the 'volumes' of the original container. Here is how:

    docker run --volumes-from <my-container-id/-name> -it busybox
    

    This will start a busybox shell. In there you have vi and other tools to inspect and fix the configuration-files.