使用 docker 复制但排除 [英] COPY with docker but with exclusion

查看:156
本文介绍了使用 docker 复制但排除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Dockerfile 中,我有

In a Dockerfile, I have

COPY . .

我想排除整个目录,在我的例子中是 node_modules 目录.

I want to exclude an entire directory, in my case, node_modules directory.

像这样:

   COPY [all but **/node_modules/**] .

这可以用 Docker 实现吗?

Is this possible with Docker?

推荐答案

在您的 docker 构建上下文目录中创建文件 .dockerignore(因此在这种情况下,很可能是 node_modules 的父目录) 一行:

Create file .dockerignore in your docker build context directory (so in this case, most likely a directory that is a parent to node_modules) with one line in it:

**/node_modules

虽然你可能只是想要:

node_modules

关于 dockerignore 的信息:https://docs.docker.com/engine/reference/builder/#dockerignore-file

Info about dockerignore: https://docs.docker.com/engine/reference/builder/#dockerignore-file

这篇关于使用 docker 复制但排除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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