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

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github