使用 --privileged 启动的 Docker 容器中出现了 tcpdump 报错问题

15

我基于Ubuntu制作了一个发送数据包的应用程序镜像,并安装了tcpdump。 当我使用--privileged启动容器并尝试运行tcpdump -i eth0时,它会报告一个错误:

root@test:/home/test# docker run --rm -ti --privileged mytliulei/xfdsend /bin/bash
root@6199493fb2b9:/# tcpdump -i eth0
tcpdump: error while loading shared libraries: libcrypto.so.1.0.0: cannot open shared object file: Permission denied

但是如果我启动 Docker 容器时不加上 --privileged 参数,那就没问题了。为什么呢?

But when I start the Docker container without --privileged, it is ok. why?

root@test:/home/test# docker run --rm -ti  mytliulei/xfdsend /bin/bash
root@c7b7e2a9ec99:/# tcpdump -i eth0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes

Docker版本:

docker version 
Client version: 1.6.0
Client API version: 1.18
Go version (client): go1.4.2
Git commit (client): 4749651
OS/Arch (client): linux/amd64
Server version: 1.6.0
Server API version: 1.18
Go version (server): go1.4.2
Git commit (server): 4749651
OS/Arch (server): linux/amd64

Dockerfile:

FROM ubuntu:14.04
MAINTAINER Liu Lei <xxx@gmail.com>

RUN apt-get update \ 
    && apt-get install -y python \
    python-dev \
    tcpdump

RUN pip2 install scapy \
    && pip2 install rpyc \
    && pip2 install robotremoteserver \
    && pip2 install daemonocle
3个回答

17

几天前我遇到了这个错误,错误似乎与以下内容有关:

https://github.com/dotcloud/docker/issues/5490

对我有用的解决方法是移动 tcpdump:

(例如:将 tcpdump 移动到 dockerfile 中)

RUN apt-get -y install tcpdump
RUN mv /usr/sbin/tcpdump /usr/bin/tcpdump

0

我在使用tcpdump时遇到了同样的问题。

root@host:/lib/x86_64-linux-gnu# tcpdump -i eth0 'port 37'
tcpdump: error while loading shared libraries: libcrypto.so.1.0.0: cannot open shared object file: Permission denied

看起来你可以通过在docker run中明确指定要运行的命令来解决这个问题。

ubuntu@host:~ docker run -- tcpdump -i any 'port 37'
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
12:57:55.247892 IP6 3000:200:199:219::81.59244 > 1000:12:12:219::7.time: UDP, length 0

对于时间服务器使用端口37。使用任何其他端口/tcpdump参数。


0

以下方法适用于我,与第一个答案相同,只是如果 Docker 已经在运行中,你可以在其中执行此操作。

root@249574360f0b:/# tcpdump
tcpdump: error while loading shared libraries: libcrypto.so.1.1: cannot open shared object file: Permission denied

root@249574360f0b:/# mv /usr/sbin/tcpdump /usr/bin/tcpdump
root@249574360f0b:/# ln -s /usr/bin/tcpdump /usr/sbin/tcpdump
root@249574360f0b:/# tcpdump
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on fpc1_int, link-type EN10MB (Ethernet), capture size 262144 bytes
10:51:22.274545 36:34:a2:0c:15:97 (oui Unknown) > Broadcast, ethertype Unknown (0x8850), length 142:
        0x0000:  3100 000c 43df 0003 ffff ffff 0000 0010  1...C...........
        0x0010:  03e8 1388 05dc 0000 0000 0010 0000 0000  ................
        0x0020:  0000 0000 0000 0000 0000 0000 0000 0000  ................

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接