How Do I Edit a File inside a Docker Container?

Better Stack Team
Updated on August 1, 2022

If you want to edit a file inside a docker container, you can follow these steps:

1. Find the id of the container

To find the id of the running container, you can use the following command:

docker container ls

The container id look something like this 8662ea2fa000

2. Launch the shell inside the container

To launch the shell inside the container, use the following command

docker exec -u 0 -it 8662ea2fa000 /bin/bash

3. Edit the file

Now that you have access to containers shell, you can install your favorite editor and start editing.

To install nano editor, run the following command:

apt update
apt install nano

Then you can start editing like this:

nano /path/to/file
Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →

Reliability is the
ultimate feature

Delightful observability tools that turn your logs & monitoring into a secret weapon for shipping better software faster.

Explore Better Stack