尽管Docker的交互式教程和常见问题,我丢失了我的数据时,容器退出。

我已经安装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新用户很重要

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


当前回答

我的建议是管理docker,使用docker compose。是一个简单的方法来管理所有docker的容器为您的项目,你可以映射版本和链接不同的容器一起工作。

文档非常容易理解,比docker的文档更好。

Docker-Compose文档

Best

其他回答

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

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

这应该有用。

如果您希望将数据持久化在容器中,您可能需要查看docker卷。访问https://docs.docker.com/engine/tutorials/dockervolumes/。docker文档是一个很好的开始

一个聪明的答案在这里如何继续从用户kgs退出的docker

docker start $(docker ps -a -q --filter "status=exited")
(or in this case just docker start $(docker ps -ql) 'cos you don't want to start all of them)

docker exec -it <container-id> /bin/bash

第二句话至关重要。所以exec被用来代替run,而且不是在映像上而是在容器id上。而且是在容器启动之后。

有以下几种方法持久化容器数据:

Docker volumes Docker commit a) create container from ubuntu image and run a bash terminal. $ docker run -i -t ubuntu:14.04 /bin/bash b) Inside the terminal install curl # apt-get update # apt-get install curl c) Exit the container terminal # exit d) Take a note of your container id by executing following command : $ docker ps -a e) save container as new image $ docker commit <container_id> new_image_name:tag_name(optional) f) verify that you can see your new image with curl installed. $ docker images $ docker run -it new_image_name:tag_name bash # which curl /usr/bin/curl

没有一个答案能解决这个设计选择的问题。我认为docker这样工作是为了防止这2个错误:

反复重启 局部的错误