为什么Docker无法将COPY文件构建到/ dev文件夹中? [英] Why can't docker build COPY files to the /dev folder?
问题描述
我想创建一个docker镜像,在其中将文件添加到 / dev
文件夹。我正在使用这个 Dockerfile
:
I want to create a docker image where I add a file to the /dev
folder. I'm using this Dockerfile
:
FROM ubuntu:bionic
COPY test.txt /dev/
在使用以下命令构建之后:
After building this with:
docker build -t test .
我得到一个Docker映像,其中 / dev
文件夹。 docker build
没有引发任何错误。
I get a docker image where nothing has been added to the /dev
folder. No error has been thrown by docker build
.
我发现这很奇怪,因为复制到其他文件夹可以正常工作。例如,
I find this very strange because copying to different folders works fine. For example
-
COPY test.txt /
-
COPY test.txt / root /
-
COPY test.txt / home /
COPY test.txt /
COPY test.txt /root/
COPY test.txt /home/
一切正常。
/ dev
文件夹有一些特殊权限吗?如何将文件复制到 / dev
文件夹?
Does the /dev
folder have some special permissions? How do I copy a file to the /dev
folder?
我在Windows上使用 Docker工具箱。
I'm using Docker Toolbox on windows.
推荐答案
/ dev
是保留用于维护设备相关资源(文件系统,磁盘等)的linux系统,并安装在特殊的文件系统上。在docker容器中,它将使用tmpfs专用文件系统重新安装,而不位于主容器文件系统( /
)上。请参见以下示例:
/dev
is a special folder on linux systems reserved to maintain the devices related ressources (filesystem, disks, etc...) and mounted on a special filesystem. In a docker container, it will be remounted with a tmpfs dedicated filesystem and is not on the main container filesystem (/
). See the following example:
$ docker run -it --rm ubuntu:18.04
root@17b9ad96ccbc:/# df -h /dev/
Filesystem Size Used Avail Use% Mounted on
tmpfs 64M 0 64M 0% /dev
在您的情况下,您的文件实际上是在构建过程中复制的,但是在一个临时文件系统中,该文件系统在构建完成后就死了。
In your case, your file was actually copied during the build but in a temporary filesystem that died as soon as the build was finished.
结论:请勿将 / dev
用作目标,请选择其他文件夹。
Conclusion: don't use /dev
as a destination, choose an other folder.
这篇关于为什么Docker无法将COPY文件构建到/ dev文件夹中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!