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条回答
萌系小妹纸
2楼-- · 2020-05-18 04:42

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.

查看更多
Animai°情兽
3楼-- · 2020-05-18 04:45

Add the following line in your Dockerfile then rebuild the docker image.

RUN apt-get update && apt-get install -y vim
查看更多
别忘想泡老子
4楼-- · 2020-05-18 04:46

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.

查看更多
我命由我不由天
5楼-- · 2020-05-18 04:52

If you actually want a small editor for simple housekeeping in a docker, use this in your Dockerfile:

RUN apt-get install -y busybox && ln -s /bin/busybox /bin/vi

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.)

查看更多
Explosion°爆炸
6楼-- · 2020-05-18 05:00

Use this:

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

Explanation of the above command

  1. apt-get update => Will update the current package
  2. apt-get install => Will install the package
  3. -y => Will by pass the permission, default permission will set to Yes.
  4. vim => Name of the package you want to install.
查看更多
ゆ 、 Hurt°
7楼-- · 2020-05-18 05:01

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:

vim scp://remoteuser@container-ip//path/to/document
查看更多
登录 后发表回答