2

I am using docker image opencv from https://hub.docker.com/r/andrewssobral/bgslibrary_opencv3/ of andrewssobral author.

First, i initialized container of the image by typing command:

docker run -it -p 5901:5901 andrewssobral/bgslibrary_opencv3 bash

And i tried install vim by command line:

apt-get install vim

But when i use exit COMMAND to go out of the container and i run it again then vim was uninstalled.

So how do i install vim or another software permanently inside docker?

gia huy
  • 329
  • 1
  • 6
  • 12

2 Answers2

5

But when i exit docker above container and i run it again then vim was uninstalled.

This is where the problem is: docker run creates a new container.

When you use docker run ... a new container is created and started based on the image you provide inside the command. It is also assigned a random name (if you don't specify one). If this container exits, you can then use docker start name and start it again. This means that if you had previously installed vim it will be there.

Solution: create a new image which includes what you need.

  1. @Sergiu proposed to use Dockerfile

  2. or another way is to save the current state of your container to a new image so that you can use it later on to create new containers with your changes included. To do this you can use docker commit

something like this:

docker commit your_modified_container_name [REPOSITORY[:TAG]]
tgogos
  • 23,218
  • 20
  • 96
  • 128
  • yes you could also do as @tgogos suggested :) as on top of the base image that someone did will also 'save' / 'commit' your extra packages / commands – Sergiu Oct 11 '17 at 11:56
3

You have two options: or you edit the Dockerfile provided by the author to add vim or you create a new Dockefile FROM the image.

Sergiu
  • 2,928
  • 3
  • 27
  • 37