How to use nano inside a Docker container?

You must have used nano throughout your work with Ubuntu and Linux for editing files. Now you are inside a docker container. You would like to edit a config file. Suddenly, nano not working? Well, there is a way for that.

First of all, you will need to get inside the /bash of your Docker container. To do that, we will first list the containers by typing docker ps -a. This would list the containers. To get inside of a container we would use

docker exec -it <container_name> /bin/bash

You can explore the container similar to a Linux file system. But when it comes to editing a file, you would get

nano not found

We will try to install nano using

apt-get update
apt-get install nano

But you will get permission error then we need to exit the container. The permission error occurred due to being logged in inside the container with not enough privileges to install a package. We will login again using root user this time.

docker exec -u 0 -it <container_name> /bin/bash

The flag -u is used to mark which user and 0 is the root user. Now we will repeat what we did and that should be it.

Now you can get back inside your container and type to test it out.

nano file_name.json

You have nano installed inside your Docker container.


Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *