docker 在 debian wheezy 7.8 中将主机/目录挂载到容器/

docker mounts host's / directory to container's / in debian wheezy 7.8

我正在我的 debian wheezy 主机上创建一个非常基本的映像。这是 Dockerfile:

FROM ubuntu:trusty
USER root

# Activate multiverse repos
RUN echo 'deb http://archive.ubuntu.com/ubuntu/ trusty universe multiverse' >> /etc/apt/sources.list
RUN echo 'deb http://security.ubuntu.com/ubuntu trusty-security universe multiverse' >> /etc/apt/sources.list
RUN echo 'deb http://archive.ubuntu.com/ubuntu/ trusty-updates universe multiverse' >> /etc/apt/sources.list
RUN apt-get update

RUN apt-get install -y supervisor

WORKDIR /

CMD ["/usr/bin/supervisord", "-n"]

为了构建图像,我使用了 docker build -t basic-ubuntu .

到运行容器,我用了docker run -d basic-ubuntu

为了进入容器,我使用了docker exec -i -t <container_id> bash

进入容器后,看到容器的根目录/和宿主机的内容是一样的。当我在容器上创建文件时,它也会在主机上创建。即使我在 Dockerfile 中添加主机上没有的某个包的 RUN apt-get install -y,我也没有在容器上找到它。实际上连容器上的 $PATH 变量都和主机一样。

这是我的环境的一些信息

host$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 7.8 (wheezy)
Release:        7.8
Codename:       wheezy

host$ docker version
Client:
 Version:      1.10.1
 API version:  1.22
 Go version:   go1.5.3
 Git commit:   9e83765
 Built:        Thu Feb 11 19:20:12 2016
 OS/Arch:      linux/amd64

Server:
 Version:      1.10.1
 API version:  1.22
 Go version:   go1.5.3
 Git commit:   9e83765
 Built:        Thu Feb 11 19:20:12 2016
 OS/Arch:      linux/amd64

docker inspect

显示的坐骑
"Mounts": []

对于完整的 docker 检查跟踪:http://pastebin.com/t4uSu4ZH

我认为问题出在 docker exec 步骤。因为构建和 运行 似乎工作正常。

I think that the problem comes from the docker exec step

确实如此,考虑到有一个容器可以将您与宿主隔离
(不同的文件系统、进程、root、用户...)

当你 "exec bash" 到一个容器时,你应该看到一个提示:

 root@<short_container_id>

如果您没有看到,那是因为您的 docker 执行程序没有正确执行。

如果您确实看到了,那么您认为主机上的内容实际上仍然是容器内容。

同样相关的是,当与 docker exec 一起使用时,-i(交互式)存在潜在错误。
参见“”。

OP amine confirms it is the case :

Issue 8755 ("Docker tty is not a tty with docker exec") 表示 -t (tty) 无法在 centos7(不是 centos6)上正确打开 tty。

即使 TERM 设置为 xterm 也会发生这种情况(不要忘记 issue 9299:当 -t通过)


Op 提到的另一个问题是:

When I went back to the howto install docker in debian, I found that in the prerequisites: "kernel must be 3.10 at minimum" and "These older versions are known to have bugs".
And my debian's kernel version is 3.2.
The solution was to upgrade to a newer debian version, with a kernel version above 3.10.

我遇到了 docker volume mount function 无法正常工作的相同问题。结果是内核版本问题。在我将 Debian 内核从 3.2 升级到 3.16 后,一切正常。

$ uname -a
Linux 3.16.0-0.bpo.4-amd64 #1 SMP Debian 3.16.7-ckt20-1+deb8u3~bpo70+1 (2016-01-19) x86_64 GNU/Linux