Cannot use vim, vi, nano, yum inside docker container

Hi Guys,

Started a dockerised application called nginx and then executed bash inside it. To my holy surprise I cannot find vim , vi or even yum inside that container.

Please forgive me as I am very much new to docker and learning.

The below commands can be used to reproduce the issue.

docker run -d --name=my_nginxtemp nginx
docker exec -i -t my_nginxtemp bash
docker commit my_nginxtemp my_nginx

My Host is Ubuntu 16.04 and I am using Latest docker-engine and docker cli

root@jim-Ubuntu1504:/home/jim/web# docker version
Client:
Version: 1.11.2
API version: 1.23
Go version: go1.5.4
Git commit: b9f10c9
Built: Wed Jun 1 22:00:43 2016
OS/Arch: linux/amd64

Server:
Version: 1.11.2
API version: 1.23
Go version: go1.5.4
Git commit: b9f10c9
Built: Wed Jun 1 22:00:43 2016
OS/Arch: linux/amd64
root@jim-Ubuntu1504:/home/jim/web#

Please don’t go on my hostname I have upgraded since 15.04 :slight_smile:
root@jim-Ubuntu1504:/home/jim/web# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04 LTS
Release: 16.04
Codename: xenial
root@jim-Ubuntu1504:/home/jim/web#

Any help would be very much appreciated !!

Many Thanks
Jim

They’re not required to run most applications, and it’s not at all unusual to install only the minimum amount of stuff required to actually run things. (A couple of containers I build don’t even have a shell!)

Also, many public images are built on a Debian or Ubuntu base, and those will have apt-get and not yum.

[If you docker run -it ubuntu:16.04 bash, there will not be a vi, you need to manually install it.]

2 Likes

Ok, I am still finding it difficult to understand the utility of “docker”. I posted the same question on another forum and response I got I would to share. nginx is the base image and they don’t have vim. I was advised to use nginx and build on the top of that.

As the previous reply stated… You can install the packages needed after the container is up… If you want the
packages installed at runtime then look into creating your own image to use. You can baseline from nginix.
Then add your packages… See references to Dockerfile or simple google finds this…

1 Like

Containers are not VM’s, thus a different approach is required.

ie. a container should only have the daemon and related tools and nothing else.

keep the editing / management tools in the host, and then mount configs to the container

1 Like

Also, if you want to be able to use nano when entering a container, you will need to set
-e TERM=xterm
in the docker run command or docker-compose.yml file for it to display correctly.

1 Like

you can run:
apt-get update
apt-get install vim -y

Actually you don’t have to use vim in container, try lighter version vim-tiny:
apt-get update
apt-get install -y vim-tiny

2 Likes

Thanks Jarfar. This helped. :slight_smile:

I am getting permission denied error while executing apt-get update as below

Reading package lists… Done
E: List directory /var/lib/apt/lists/partial is missing. - Acquire (13: Permission denied)

1 Like

Hi,

how do i install vim in RHEL

yum install vim

bash: yum: command not found

yum install vim-enhanced

bash: yum: command not found

Why do you need an editor inside the container? You should be writing your own Dockerfile and/or docker-compose file that takes the stock nginx container image and customizes it to your liking. Then you just launch that.

I do agree there are occasions when it’s faster to experiment by changing a file on the fly, but even then I use docker cp to copy the file out, make my changes on the host and then docker cp the file back in. Or I just bind mount the config dir and make my edits on the host.

So please describe the problem you are trying to solve and maybe we can suggest a better work flow for you.

Did you found a fix for this?

I do have a docker container running with custom user with read-only mode for security reasons. Now the trade off is debuggability, we are unable to install any text editors.