Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

docker

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.

like image 945
learner Avatar asked Jun 08 '16 06:06

learner


People also ask

Can I SSH into a container?

The SSH method works fine for Docker containers, too. That said, you can SSH into a Docker container using Docker's built-in docker exec . If you do not need an interactive shell, you can also use the docker attach command to connect the host's stdin and stdout to the running container and execute remote commands.

How do I view files inside a Docker container?

In the latest versions of Docker, something like this is possible: docker exec <container> bash . So, you just open a shell inside the container. Similarly, you can do: docker exec <container> ls <dir path> and docker exec <container> cat <file path> .

How do I edit running files in Docker container?

To verify, use the cat command to print the contents inside the file. In this way, you can use any editor of your choice to edit files inside the container. If you already have a container running in the background, you can even use the Docker exec command to get access to the bash of the container.


2 Answers

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.

like image 125
Bhuwan Gautam Avatar answered Oct 02 '22 11:10

Bhuwan Gautam


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
like image 12
VonC Avatar answered Oct 02 '22 13:10

VonC