31

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
learner
  • 2,480
  • 10
  • 50
  • 94
  • That just happened to me today! I've seen in some topics also to change the Dockerfile. I will try it – Geiser Jun 08 '16 at 13:24
  • Possible duplicate of [How do I edit a file after I shell to a Docker container?](https://stackoverflow.com/questions/30853247/how-do-i-edit-a-file-after-i-shell-to-a-docker-container) – Steve Chambers Sep 18 '18 at 10:57

5 Answers5

42

sudo apt-get update
sudo apt-get install vim

I had the same issue. I followed the simple two steps above and it worked like a charm.

Bhuwan Gautam
  • 421
  • 4
  • 2
13

To my holy surprise I cannot find vim , vi or even yum inside that container.

It simply depends on the nginx image and its base image: if vim never was installed there, your container won't find it.

You could build your own image, starting from nginx, and adding the software you need.

FROM nginx
RUN apt-get update
RUN apt-get install vim
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • But would that image have access to internet ? Say if you want to install any additional software (s)? What does surprise me is it is eventually an OS and web server on the top of that so why not having the capability to install software ? – learner Jun 08 '16 at 07:00
  • @learner that image would have the same internet access that your host. If you are behind a proxy, use http://stackoverflow.com/a/35286398/6309 and make sure your docker daemon is aware of that proxy (https://docs.docker.com/engine/admin/systemd/#http-proxy) – VonC Jun 08 '16 at 07:02
  • Cool. I would build that image ! Many Thanks – learner Jun 08 '16 at 07:03
  • 1
    Yeah, it has same access as like host. Is that because of Bridge networking of docker? Want to understand that – learner Jun 08 '16 at 08:22
  • Yes, that is what is detailed in https://docs.docker.com/engine/userguide/networking/dockernetworks/ – VonC Jun 08 '16 at 08:34
  • @ VonC, your answer lacks one or 2 RUN it seems :-) – user2915097 Jun 08 '16 at 08:36
10

Adding some more description for beginners like me: Some containers are built on ubuntu and hence you wont even find yum package manager which is specific to RedHat/CentOS.

1. Get inside the container using exec:

username@hostname:/home/username $ docker container exec -it container_image_name bash

2. Figure out OS on which container image was built and act accordingly Now, to figure out on which OS the container image was built, we can also check the OS version once we are inside that container using below:

root@5e9d0e3c1001:/# cat /etc/*release*
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
root@5e9d0e3c1001:/#

Then perform below(the reason we are doing update is that it's mandatory before installing for the first time):

root@5e9d0e3c1001:/# apt-get update
root@5e9d0e3c1001:/# apt-get install vim

Reference: https://forums.docker.com/t/cannot-use-vim-vi-nano-yum-inside-docker-container/14905

ok_karthik
  • 101
  • 1
  • 4
  • Running containers as root and even with all capabilities enabled is a security risk. Secure servers are also air-gapped, so the install would fail for that reason too. – mirekphd Apr 14 '22 at 04:35
5

This is our editor of last resort:

echo "This is a workaround." > file.txt
echo "Added more text." >> file.txt
cat file.txt
mirekphd
  • 4,799
  • 3
  • 38
  • 59
1

You can create a Dockerfile to use the nginx docker image and modify it with you want to add...

FROM nginx
RUN ["apt-get","update"]
RUN ["apt-get","install","-y","vi"]
KatyGB
  • 11
  • 2