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
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
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.Add the following line in your Dockerfile then rebuild the docker image.
The command to run depends on what base image you are using.
For Alpine,
vi
is installed as part of the base OS. Installingvim
would be:For Debian and Ubuntu:
For CentOS,
vi
is usually installed with the base OS. Forvim
: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.
If you actually want a small editor for simple housekeeping in a docker, use this in your Dockerfile:
I used it on an Ubuntu 18 based docker. (Of course you might need an
RUN apt-get update
before it but if you are making your own Docker file you probably already have that.)Use this:
Explanation of the above command
Alternatively, keep your docker images small by not installing unnecessary editors. You can edit the files over ssh from the docker host to the container: