小编典典

容器退出时我丢失了数据

docker

尽管有Docker的Interactive教程常见问题解答,但当容器退出时,我仍然丢失了数据。

我已经按照以下说明安装了Docker:http
:
//docs.docker.io/en/latest/installation/ubuntulinux
在ubuntu 13.04上没有任何问题。

但是退出时它将丢失所有数据。

iman@test:~$ sudo docker version
Client version: 0.6.4 
Go version (client): go1.1.2 
Git commit (client): 2f74b1c 
Server version: 0.6.4 
Git commit (server): 2f74b1c 
Go version (server): go1.1.2 
Last stable version: 0.6.4


iman@test:~$ sudo docker run ubuntu ping
2013/10/25 08:05:47 Unable to locate ping 
iman@test:~$ sudo docker run ubuntu apt-get install ping
Reading package lists... 
Building dependency tree... 
The following NEW packages will be installed: 
  iputils-ping 
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. 
Need to get 56.1 kB of archives. 
After this operation, 143 kB of additional disk space will be used. 
Get:1 http://archive.ubuntu.com/ubuntu/ precise/main iputils-ping amd64 3:20101006-1ubuntu1 [56.1 kB] 
debconf: delaying package configuration, since apt-utils is not installed 
Fetched 56.1 kB in 0s (195 kB/s) 
Selecting previously unselected package iputils-ping. 
(Reading database ... 7545 files and directories currently installed.) 
Unpacking iputils-ping (from .../iputils-ping_3%3a20101006-1ubuntu1_amd64.deb) ... 
Setting up iputils-ping (3:20101006-1ubuntu1) ... 
iman@test:~$ sudo docker run ubuntu ping
2013/10/25 08:06:11 Unable to locate ping 
iman@test:~$ sudo docker run ubuntu touch /home/test
iman@test:~$ sudo docker run ubuntu ls /home/test
ls: cannot access /home/test: No such file or directory

我还通过相同结果的交互式会话对其进行了测试。我忘记了什么吗?

编辑:对于新DOCKER用户的重要

正如@ mohammed-noureldin和其他人所说,实际上这 不是 退出容器 。每次它只是创建一个新的容器。


阅读 514

收藏
2020-06-17

共1个答案

小编典典

您需要提交对容器所做的更改,然后运行它。尝试这个:

sudo docker pull ubuntu

sudo docker run ubuntu apt-get install -y ping

然后使用以下命令获取容器ID:

sudo docker ps -l

提交对容器的更改:

sudo docker commit <container_id> iman/ping

然后运行容器:

sudo docker run iman/ping ping www.google.com

这应该工作。

2020-06-17