How to edit files within docker containers

Disclaimer You have probably heard countless times that you should never edit a docker container’s state, or editing container state is an anti-pattern, or if you need to edit a container’s state you should use volumes. That advice is good advice and so this article starts with a disclaimer. If you really need to edit file(s) within a docker container you most likely should do it in one of two ways: Use a docker volume; or Make any edits to the file(s) part of the image’s [crayon-62fe23380c48b641873476-i/] I would recommend never editing a file in production unless the file is part of a mounted docker volume (and even then you should exercise caution not to inadvertently affect the production system). That being said, making minor, ephemeral edits to files within a development environment outside of production can be a quick and easy way to test a change and/or aid in debugging. If the edits you make are not minor consider using the one of the two methods listed above to make changes to your files. Our running example With the disclaimer out-of-the way we can move on to our running example: We have an Apache web server (httpd) container that we are having problems with. We would like to edit the server’s configuration file to increase the [crayon-62fe23380c498592263216-i/]  so that more logging information is output and debugging (hopefully) becomes easier. The configuration file in question is not part of a volume so we will edit it from within the container. There are two ways in which we can get inside the running container to edit the configuration file: Open a shell and edit the file from the command line. Remote into the container and make the changes with our editor. This article covers the first method but in practice it … Continue reading How to edit files within docker containers