How to run vi on docker container?
I have installed docker on my host virtual machine. And now want to create a file using vi
.
But it's showing me an error:
bash: vi: command not found
Solution 1:
login into container with the following command:
docker exec -it <container> bash
Then , run the following command .
apt-get update
apt-get install vim
Solution 2:
The command to run depends on what base image you are using.
For Alpine, vi
is installed as part of the base OS. Installing vim
would be:
apk -U add vim
For Debian and Ubuntu:
apt-get update && apt-get install -y vim
For CentOS, vi
is usually installed with the base OS. For vim
:
yum install -y vim
This should only be done in early development. Once you get a working container, the changes to files should be made to your image or configs stored outside of your container. Update your Dockerfile and other files it uses to build a new image. This certainly shouldn't be done in production since changes inside the container are by design ephemeral and will be lost when the container is replaced.
Solution 3:
Your container probably haven't installed it out of the box.
Run apt-get install vim
in the terminal and you should be ready to go.