我有一个应用程序正在尝试移至 Docker 容器中。我的大部分功能都可以正常工作,但是应用程序中需要提升权限的部分(使用套接字和配置网络参数)似乎无法正常工作。
我尝试过的:
--privileged
旗帜--cap-add=NET_ADMIN
旗帜--security-opt apparmor=unconfined --security-opt seccomp=unconfined
--net=host \
选项。这是我遇到的错误:
Process Process-2:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
self.run()
File "/usr/local/lib/python3.9/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/app/support_files/wizard_configuration_routines.py", line 781, in find_device
device_list = scan_subnet('192.168.30.0/24',g_interface)
File "/app/support_files/wizard_configuration_routines.py", line 757, in scan_subnet
answered, unanswered = scapy.arping(subnet,verbose=False,iface=g_interface)
File "/usr/local/lib/python3.9/site-packages/scapy/layers/l2.py", line 890, in arping
ans, unans = srp(
File "/usr/local/lib/python3.9/site-packages/scapy/sendrecv.py", line 687, in srp
s = iface.l2socket()(promisc=promisc, iface=iface,
File "/usr/local/lib/python3.9/site-packages/scapy/arch/linux.py", line 484, in __init__
self.ins = socket.socket(
File "/usr/local/lib/python3.9/socket.py", line 232, in __init__
_socket.socket.__init__(self, family, type, proto, fileno)
PermissionError: [Errno 1] Operation not permitted
以下是相关文件
Dockerfile
# Slim version of Python
FROM python:3.9-slim
# Download Package Information
RUN apt update -y
# Install Tkinter
RUN apt install tk -y
# Install fontconfig
RUN apt install fontconfig -y
# Install Pillow
RUN python3 -m pip install Pillow
RUN python3 -m pip install ouster-sdk
RUN python3 -m pip install scapy
RUN python3 -m pip install customtkinter
RUN apt install net-tools -y
RUN fc-cache -f -v
# Commands to run Tkinter application
CMD ["/app/SCOT_wizard.py"]
ENTRYPOINT ["python3"]
build.sh
sudo docker build -t tkinter_in_docker .
运行.sh
sudo docker run -u=$(id -u $USER):$(id -g $USER) \
-e DISPLAY=$DISPLAY \
-v /tmp/.X11-unix:/tmp/.X11-unix:rw \
-v $(pwd)/app:/app \
-v $(pwd)/logs:/logs \
-v $(pwd)/records:/records \
-v $(pwd)/fonts:/.fonts\
-w /app \
--privileged \
--net=host \
--rm \
tkinter_in_docker
尝试以 root 身份运行容器。为此,您可以将以下行添加到 Dockerfile 中:
USER root
或者使用 -u 参数运行容器:
docker run -u root <image-name>