为什么docker无法将COPY文件构建到/dev文件夹? [英] Why can't docker build COPY files to the /dev folder?

查看:58
本文介绍了为什么docker无法将COPY文件构建到/dev文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个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/

一切正常.

/dev 文件夹是否具有某些特殊权限?如何将文件复制到/dev 文件夹?

Does the /dev folder have some special permissions? How do I copy a file to the /dev folder?

我正在使用 Windows上的Docker工具箱.

推荐答案

/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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆