u123
u123

Reputation: 16287

Vi or Vim not found on Ubuntu docker container

I have an nginx-controller container running in k8s based on an Ubuntu image:

Image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.25.0

Inside the container:

$ kubectl exec -it nginx-ingress-controller-xyz bash
$ uname -a
Linux nginx-ingress-controller-xyz 4.15.0-1111-azure #123~16.04.1-Ubuntu SMP Sat Mar 20 01:52:07 UTC 2021 x86_64 GNU/Linux

Seems that neither vi or vim is available:

$ vi
bash: vi: command not found
$ vim
bash: vim: command not found

I thought vi/vim would always be on a linux machine?

Upvotes: 1

Views: 12038

Answers (4)

romainl
romainl

Reputation: 196546

A vi command that behaves as per the POSIX specification is mandatory for an OS to call itself Unix.

Ubuntu and other Linux-based operating systems are not certified and being certified is not exactly a goal so all they do is follow the specification as closely as they want/need/can. Therefore, it is unreasonable to expect vi to "always be on a linux machine" or that vi command to be provided by Vim. There is simply no guarantee.

Moreover, it is customary to make Docker images meant for production as lightweight (and secure) as possible by removing as much cruft as possible. You don't need vi to run your Ingress Controller so it isn't there.

Upvotes: 2

tanish
tanish

Reputation: 67

You won't find many commonly available programs in docker images. Because these images are made to be lightweight.
You can install vim on an ubuntu image by

apt-get update && apt-get install vim

Upvotes: 4

Felix Du
Felix Du

Reputation: 115

If there is apt or apt-get command in your container, just run apt update && apt install vim, otherwise you can try:
nsenter -t <Pid> -n -m vi <your-file> to reuse the tools on your host but change the namespace.

Upvotes: 0

rezshar
rezshar

Reputation: 630

In this situation, For me, this method always works. At first go to your container and then use these commands:

apt update
apt install vim

or

apt update
apt install nano

Upvotes: 0

Related Questions