Docker Container Install Vim



I’m just getting started with Docker. I’ve thought for years that containerization is a great idea, but I haven’t actually done anything with containers yet. Time to get started.

I ran through a couple tutorials on the Docker docs site and created a cloud.docker.com account to get some basic familiarity.

I found the CentOS container repository on Docker Hub: https://hub.docker.com/_/centos/

Verify Docker Installation Working with Docker Images. A Docker image is a read-only template file with instructions for creating a Docker container. You can either create your custom images or you can only use those created by others and published in the Docker Hub, the world’s largest library and community for container images. 1) yum install vim 2) vim /etc/yum.conf 3) Remove the tsflags=nodocs line a = down arrow to that line = delete that line = esc =:wq 4) yum install man-pages 5) man ls 6) repeat the docker commit steps again. Install Vim on Docker Container. Most docker containers are based on Debian and Ubuntu Linux. So you should able install vim on docker with apt-get command. Apt-get update apt-get install vim. If the docker container is a redhat based distribution, use the yum install command. Yum install vim Install nano Text Editor on Docker. On debian based. Docker exec apt-get update && apt-get install -y vim. But this will be limited to the container in which vim is installed. To make it available to all the containers, edit the Dockerfile and add. RUN apt-get update && apt-get install -y vim. Or you can also extend the image in the new Dockerfile and add above command. The following steps explain how you should go about creating a Docker File. Step 1 − Create a file called Docker File and edit it using vim. Please note that the name of the file has to be 'Dockerfile' with 'D' as capital. Step 2 − Build your Docker File using the following instructions.

Let’s try running it!

$ docker pull centos
$ docker run centos

Did it do anything? It looks like it did something. At least, it didn’t give me an error. What did it do? How do I access it?

$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

Nothing is actively running. That makes sense, because we’re not telling the containerized OS to do anything — it starts, it doesn’t have anything to do, and so it shuts down immediately. Instead we can tell it to run interactively and with a terminal by specifying a couple options:

-i, --interactive
-t, --tty
(“allocate a pseudo-TTY”, i.e. a terminal)
(see docker run --help for details)

Docker Container Install Vim

$ docker run -i -t centos
[root@4f0b435cdbd7 /]#

I’m in!

What if I want to modify the container? Right now it is pretty bare-bones. For example, this doesn’t even have man installed:

Docker Container Install Vimeo

[root@4f0b435cdbd7 /]# man man
bash: man: command not found

[root@4f0b435cdbd7 /]# yum install man
...
[root@4f0b435cdbd7 /]# man man
No manual entry for man

Quite the improvement! Now we need to save our change:

[root@4f0b435cdbd7 /]# exit

$ docker commit 4f0b435cdbd7 man-centos
$ docker run -i -t man-centos

[root@953c512d6707 /]# man man
No manual entry for man

Progress! Now we have a CentOS container where man is already installed. Exciting.

Container

I can’t (that I know of) inspect the container and know whether or not man is installed without running it. That’s fine for many cases, but next I will attempt to figure out how specify via a Dockerfile that man is installed.

Almost all docker containers do not have a text editor by default. But most of the time you will need a command line text editor for edit files inside a docker container.

Install Vim on Docker Container

Most docker containers are based on Debian and Ubuntu Linux. So you should able install vim on docker with apt-get command.

If the docker container is a redhat based distribution, use the yum install command.

Install nano Text Editor on Docker

Install Vim In Docker Container

On debian based containers, install nano editor with apt-get command.

On a Redhat/CentOS based container, Type:

Install Vim On Docker Container

To use the nano text editor you will also need to set 'TERM' environment variable.