opencvdockervimpermanent

How can i save the data and softwares inside docker container permanently?


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?


Solution

  • 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]]