尽管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和其他人所说,实际上这不是一个容器退出。每次它都会创建一个新容器。
除了Unferth的答案,建议创建一个Dockerfile。
在一个空目录中,创建一个名为“Dockerfile”的文件,包含以下内容。
FROM ubuntu
RUN apt-get install ping
ENTRYPOINT ["ping"]
使用Dockerfile创建一个映像。让我们使用一个标签,这样我们就不需要记住十六进制的图像编号。
$ docker build -t iman/ping .
然后在容器中运行图像。
$ docker run iman/ping stackoverflow.com
除了Unferth的答案,建议创建一个Dockerfile。
在一个空目录中,创建一个名为“Dockerfile”的文件,包含以下内容。
FROM ubuntu
RUN apt-get install ping
ENTRYPOINT ["ping"]
使用Dockerfile创建一个映像。让我们使用一个标签,这样我们就不需要记住十六进制的图像编号。
$ docker build -t iman/ping .
然后在容器中运行图像。
$ docker run iman/ping stackoverflow.com
类似的问题(仅靠Dockerfile无法解决)将我带到了这个页面。
0阶段:
对于所有人来说,希望Dockerfile可以修复它:直到——dns和——dns-search将出现在Dockerfile支持中-没有办法将基于intranet的资源集成到。
stage 1:
after building image using Dockerfile (by the way it's a serious glitch Dockerfile must be in the current folder), having an image to deploy what's intranet based, by running docker run script. example:
docker run -d \
--dns=${DNSLOCAL} \
--dns=${DNSGLOBAL} \
--dns-search=intranet \
-t pack/bsp \
--name packbsp-cont \
bash -c " \
wget -r --no-parent http://intranet/intranet-content.tar.gz \
tar -xvf intranet-content.tar.gz \
sudo -u ${USERNAME} bash --norc"
阶段2:
应用docker运行脚本在守护进程模式提供本地DNS记录有能力下载和部署本地的东西。
重点:运行脚本应该以类似/usr/bin/sudo -u ${USERNAME} bash——norc结尾,以便在安装脚本结束后仍然保持容器运行。
不,不可能在完全自动化的交互模式下运行容器,因为它将保持在内部shall命令提示符中,直到按下CTRL-p CTRL-q。
不,如果交互bash不会在安装脚本的末尾执行,容器将在脚本执行完成后立即终止,丢失所有安装结果。
stage 3:
container is still running in background but it's unclear whether container has ended installation procedure or not yet. using following block to determine execution procedure finishes:
while ! docker container top ${CONTNAME} | grep "00[[:space:]]\{12\}bash \--norc" -
do
echo "."
sleep 5
done
the script will proceed further only after completed installation. and this is the right moment to call: commit, providing current container id as well as destination image name (it may be the same as on the build/run procedure but appended with the local installation purposes tag. example: docker commit containerID pack/bsp:toolchained.
see this link on how to get proper containerID
阶段4:容器已经使用本地安装更新,并且已经提交到新分配的映像中(添加了目的标记的映像)。现在可以安全地停止容器运行了。例如:docker stop packbsp-cont
Stage5:任何带有本地安装的容器需要运行的时候,使用之前保存的映像启动它。
示例:docker run -d -t pack/bsp:toolchained