问题描述
我创建了2个Docker容器,并尝试在ubuntu,debian上安装一些应用程序,以及-mc,ping,traceroute ..等软件包.但是,每当我退出容器时,我都会从那里松散所有东西.命令来保存我的配置?
I've created 2 docker containers and I tried to install some application on ubuntu,debian and some packages as - mc, ping, traceroute.. but whenever I exit from the container I loose everything from there.. Is any docker command to save my config?
root@ubuntu:/tmp# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
debian latest 2b98c9851a37 4 weeks ago 100MB
ubuntu latest f975c5035748 5 weeks ago 112MB
ubuntu 14.04 dc4491992653 2 months ago 222MB
root@ubuntu:/tmp# docker ps -q
a3a1c08a3dbd
1c1990b6f014
推荐答案
默认情况下,不备份Docker容器文件系统,并且在删除容器时将其删除.为了在Docker容器中保留某些位置,您必须使用用户卷.
By default, a Docker containers file system is not backed-up and will be deleted when the container gets deleted. In order to persist certain locations inside a Docker container you have to user volumes.
对于您的情况,您将必须保留某些位置,例如/bin
,'/usr/bin',因为这些文件夹将包含要安装的工具的二进制文件.
For your case, you will have to persist certain locations such as /bin
, '/usr/bin' since these folder will container the binaries for the tools that you are installing.
docker run -it -v bin:/bin -v usr_bin:/usr/bin ubuntu bash
这将起作用,但是更好的方法是使用一系列 RUN
指令创建Dockerfile并安装所需的工具.这将提供一个Docker映像,其中将包含您安装的所有工具,并且可以实例化多次以创建多个容器.
This will work however a better approach is to create a Dockerfile and install the tools you need using a sequence of RUN
instructions. This will give a docker image that will contain all the tools you installed, andcan be instantiated multiple times to create multiple containers.
FROM <base-image>
RUN apt-get install iputils-ping
这篇关于在Docker容器上保存配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!