简体   繁体   English

docker build 挂在包含许多文件的目录中

[英]docker build hangs in directory with many files

Windows 10. I have in folder just: Windows 10。我在文件夹中只有:

app (directory with many files)
Dockerfile (simpliest docker file)

I run "docker build ."我运行“docker build”。 and it just hangs.它只是挂起。 If I remove "app" directory.如果我删除“app”目录。 Build runs ok.构建运行正常。 In docker file just one line:在 docker 文件中只有一行:

FROM node

Didn't find any issues like that.没有发现类似的问题。 It fills like it tries to scan the directory or something.它填充就像它试图扫描目录或其他东西一样。

Any advice?有什么建议吗?

UPD: It seems that I should use .dockerignore https://docs.docker.com/engine/reference/builder/#/dockerignore-file UPD:似乎我应该使用 .dockerignore https://docs.docker.com/engine/reference/builder/#/dockerignore-file

When you run docker build ... the Docker client sends the context (recursive contents of the directory) via REST to the Docker daemon for building.当您运行docker build ... Docker 客户端通过 REST 将上下文(目录的递归内容)发送到 Docker 守护程序以进行构建。 If that context is large, this could take some time (depending on a variety of factors, if your daemon is local / remote, platform maybe, etc...).如果该上下文很大,这可能需要一些时间(取决于各种因素,如果您的守护进程是本地/远程的,可能是平台等...)。

How long are you giving it to hang before giving up?在放弃之前,你给它了多久? Could be that it's still just working?可能它仍然在工作吗? Or could be that the context was so large maybe the client / daemon experienced an issue.或者可能是因为背景是如此之也许是客户端/守护程序时遇到了问题。 Checking the (client / daemon) logs would help debug that.检查(客户端/守护程序)日志将有助于调试。

And yes, a .dockerignore file (basically a .gitignore but for Docker context ) is probably what you're looking for, unless you need the contents of the app directory during your build.是的,一个.dockerignore文件(基本上是一个.gitignore但对于 Docker上下文)可能就是你正在寻找的,除非你在构建过程中需要app目录的内容。

Your Dockerfile should be put in the directory that only includes it's build context.你的 Dockerfile 应该放在只包含它的构建上下文的目录中。 For example, if you are building a spring-boot app, you can put the Dockerfile right under /app, as shown in this official docker sample.例如,如果您正在构建一个 spring-boot 应用程序,您可以将 Dockerfile 放在 /app 下,如这个官方 docker 示例中所示。

Docker's documentation : Docker 的文档

In most cases, it's best to start with an empty directory as context and keep your Dockerfile in that directory.在大多数情况下,最好从一个空目录作为上下文开始,并将 Dockerfile 保存在该目录中。 Add only the files needed for building the Dockerfile.仅添加构建 Dockerfile 所需的文件。

Warning: Do not use your root directory, /, as the PATH as it causes the build to transfer the entire contents of your hard drive to the Docker daemon.警告:不要使用根目录 / 作为 PATH,因为它会导致构建将硬盘驱动器的全部内容传输到 Docker 守护程序。

I've seen that simple docker examples put dockerfile in the root directory, but for complicated examples like the one I posted above, the dockerfile is put only in it's relevant directory.我已经看到简单的 docker 示例将 dockerfile 放在根目录中,但对于我上面发布的复杂示例,dockerfile 仅放在其相关目录中。 You can dig through the dockersamples repository and find your case.您可以浏览dockersamples存储库并找到您的案例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM