How to run vi on docker container?

2020-05-18 04:14发布

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

10条回答
ゆ 、 Hurt°
2楼-- · 2020-05-18 05:03

Use below command in Debian based container:

apt-get install vim-tiny

Complete instruction for using in Dockerfile:

RUN apt-get update && apt-get install --no-install-recommends -y \   
 vim-tiny \  
 && apt-get clean && rm -rf /var/lib/apt/lists/*

It doesn't install unnecessary packages and removes unnecessary downloaded files, so your docker image size won't increase dramatically.

查看更多
成全新的幸福
3楼-- · 2020-05-18 05:07

login into container with the following command:

docker exec -it <container> bash

Then , run the following command .

apt-get update
apt-get install vim
查看更多
Lonely孤独者°
4楼-- · 2020-05-18 05:07

Inside container(in docker, not in VM), by default these are not installed. Even apt-get, wget will not work. My VM is running on Ubuntu 17.10. For me yum package manaager worked.

Yum is not part of debian or ubuntu. It is part of red-hat. But, it works in Ubuntu and it is installed by default like apt-get

Tu install vim, use this command

yum install -y vim-enhanced 

To uninstall vim :

yum uninstall -y vim-enhanced 

Similarly,

yum install -y wget 
yum install -y sudo 

-y is for assuming yes if prompted for any qustion asked after doing yum install packagename

查看更多
ら.Afraid
5楼-- · 2020-05-18 05:09

To install within your Docker container you can run command

docker exec apt-get update && apt-get install -y vim

But this will be limited to the container in which vim is installed. To make it available to all the containers, edit the Dockerfile and add

RUN apt-get update && apt-get install -y vim

or you can also extend the image in the new Dockerfile and add above command. Eg.

FROM < image name >

RUN apt-get update && apt-get install -y vim

查看更多
登录 后发表回答