Python Docker和fcntl OSError Errno 22无效参数
我遇到了一个奇怪的问题,我不知道如何继续 我有docker 18.09.2,在运行Ubuntu 18.04的VMware ESXi 6.5虚拟机上构建6247962。我有docker 19.03.3,在运行Ubuntu 18.04的Azure虚拟机上构建a872fc2f86。我在两台主机上以及不同的docker容器中运行了以下小测试脚本:Python Docker和fcntl OSError Errno 22无效参数,python,linux,docker,ubuntu,fcntl,Python,Linux,Docker,Ubuntu,Fcntl,我遇到了一个奇怪的问题,我不知道如何继续 我有docker 18.09.2,在运行Ubuntu 18.04的VMware ESXi 6.5虚拟机上构建6247962。我有docker 19.03.3,在运行Ubuntu 18.04的Azure虚拟机上构建a872fc2f86。我在两台主机上以及不同的docker容器中运行了以下小测试脚本: #!/usr/bin/python3 import fcntl import struct image_path = 'foo.img' f_obj =
#!/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的VM上使用上述docker文件创建docker映像,则上述结果与主机相同
如果我在运行docker 19.03.3的VM上使用上述docker文件创建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 run -it -v $PWD:/these_work ubuntu:18.04 bash
容器中/this\u work
目录下的文件工作正常,但是仅可从容器中访问的其他文件导致[Errno 22]无效参数
我来这里是因为一个yocto构建错误,该错误来自于访问filemap.py中blocksize的几乎相同的方法:
# 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")
我发现装载的卷不一定要与主机共享,它可以只是一个docker卷(对于我来说,答案并不清楚)。我还发现,如果我将这个卷装载到容器中的非空目录中,Docker会自动将目录内容存储到这个卷中,这样我就不必在容器中做任何额外的更改,一切都可以正常工作。谢谢你的解决方案!
# 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")