複製被忽略的檔案

注意

此檢查為實驗性功能,預設為停用。如需啟用,請參閱實驗性檢查

輸出

Attempting to Copy file "./tmp/Dockerfile" that is excluded by .dockerignore

說明

當您在 Dockerfile 中使用 ADD 或 COPY 指令時,應確保要複製到映像檔中的檔案與 .dockerignore 中的模式不相符。

建置映像檔時,與 .dockerignore 檔案中的模式相符的檔案不會出現在映像檔的建置環境中。嘗試複製或新增建置環境中遺漏的檔案將導致建置錯誤。

範例

使用指定的 .dockerignore 檔案

*/tmp/*

❌ 不良示範:嘗試複製被 .dockerignore 排除的檔案 "./tmp/Dockerfile"

FROM scratch
COPY ./tmp/helloworld.txt /helloworld.txt

✅ 良好示範:複製未被 .dockerignore 排除的檔案

FROM scratch
COPY ./forever/helloworld.txt /helloworld.txt