「.dockerignore」- 控制加入构建文中的内容

认识

You can use a .dockerignore file to exclude files or directories from the build context. This helps avoid sending unwanted files and directories to the builder, improving build speed, especially when using a remote builder.

文档:https://docs.docker.com/build/concepts/context/#dockerignore-files

场景 | 当构建镜像时,忽略文件 | .dockerignore

Do not ignore .dockerignore (it’s expensive and potentially dangerous)
COPY with docker but with exclusion

dockerignore | 学习笔记

在上下文目录中,可以创建 .dockerignore 文件(类似于 .gitignore 文件),防止在 Build Context 中的某些文件被传到 Docker Server 中。

该文件中的匹配模式规则采用 Go 语言中的 filepath.Match() 函数。

忽略所有文件,仅包含个别文件

docker – Dockerignore: Ignore everything except a file and the Dockerfile – Stack Overflow

# Ignore everything
*

# Allow files and directories
!/file.txt
!/src