Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 
like image 791
Krati Jain Avatar asked Jul 20 '15 11:07

Krati Jain


People also ask

Does Docker have vim?

2. For Ubuntu/Debian. The official Docker image of Ubuntu and Debian does not contain the vim package.


2 Answers

login into container with the following command:

docker exec -it <container> bash 

Then , run the following command .

apt-get update apt-get install vim 
like image 97
arunprakashpj Avatar answered Oct 02 '22 02:10

arunprakashpj


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.

like image 29
BMitch Avatar answered Oct 02 '22 00:10

BMitch