简体   繁体   中英

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?

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

您有两个选择:或者编辑作者提供的Dockerfile以添加vim,或者映像创建新的Dockefile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM