我遇到了一个奇怪的问题,我不知道如何继续。
我在运行 Ubuntu 18.04 的 VMware ESXi 6.5 虚拟机上安装了 docker 18.09.2(内部版本 6247962)。我有 docker 19.03.3,在运行 Ubuntu 18.04 的 Azure 虚拟机上构建 a872fc2f86。我有以下小测试脚本,可以在两台主机和不同的 docker 容器中运行:
#!/usr/bin/python3
import fcntl
import struct
image_path = 'foo.img'
f_obj = open(image_path, 'rb')
binary_data = fcntl.ioctl(f_obj, 2, struct.pack('I', 0))
bsize = struct.unpack('I', binary_data)[0]
print('bsize={0}'.format(bsize))
exit(0)
我运行“ps -ef >foo.img”来获取 foo.img 文件。上述脚本在两台虚拟机上的输出均为 bsize=4096。
我在两个虚拟机上都有以下 Dockerfile:
FROM ubuntu:19.04
RUN apt-get update && \
apt-get install -y \
python \
python3 \
vim
WORKDIR /root
COPY testfcntl01.py foo.img ./
RUN chmod 755 testfcntl01.py
如果我在运行 docker 18.09.2 的虚拟机上使用上述 Dockerfile 创建一个 docker 镜像,上面的结果将与主机相同。
如果我在运行 docker 19.03.3 的虚拟机上使用上述 Dockerfile 创建 docker 镜像,则会出现以下错误:
root@d317404714a6:~# ./testfcntl01.py
Traceback (most recent call last):
File "./testfcntl01.py", line 9, in <module>
binary_data = fcntl.ioctl(f_obj, 2, struct.pack('I', 0))
OSError: [Errno 22] Invalid argument
我比较了主机之间的 docker 目录结构、daemon.json 文件、日志、“docker 信息”。它们看起来是一样的。我尝试使用 FROM ubuntu:18.04 以及 ubuntu:19.04。我尝试过 python2 和 python3。结果相同。
我不知道为什么 fcntl 仅在运行 docker 19.03.3 的 Azure VM 上的 docker 容器上失败。 docker 在 18 到 19 之间是否发生了一些变化可能导致了这种情况?我需要进行一些配置更改才能使其正常工作吗?我还缺少什么吗?
任何帮助将不胜感激。
谢谢
刘易斯·穆伦坎普
更新01:
我正在按照步骤 here准备我自己的自定义 Ubuntu 18.04 VHD 以在 Azure 中使用。我开始使用刚刚从 Ubuntu 网站下载的 ubuntu-18.04.3-live-server-amd.iso 对 Ubuntu Server 18.04 进行通用安装。下面的测试在新安装的虚拟机上运行得很好。我完成这一步
sudo apt-get install linux-generic-hwe-18.04 linux-cloud-tools-generic-hwe-18.04
然后我的测试失败了。因此,我认为这些硬件支持包存在一些问题。
最佳答案
我遇到了一个非常类似的错误,并发现如果文件位于已安装的卷中(至少由主机拥有),则它不会失败。即:
docker run -it -v $PWD:/these_work ubuntu:18.04 bash
/these_work
下的文件容器中的目录有效,但是只能从容器内访问的其他文件导致 [Errno 22] Invalid Argument
.
我从 yocto 构建错误中来到这里,该错误来自于访问 filemap.py
内的 block 大小的几乎相同的方法。 :
# Get the block size of the host file-system for the image file by calling
# the FIGETBSZ ioctl (number 2).
try:
binary_data = fcntl.ioctl(file_obj, 2, struct.pack('I', 0))
except OSError:
raise IOError("Unable to determine block size")
关于python - Docker 和 fcntl OSError Errno 22 参数无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58506448/