From 5011f61213df9cc418427b1804a8754fb4d68347 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 21 Jul 2021 12:03:31 +0200 Subject: [PATCH] Fix Dockerfile COPY/ADD examples without a trailing slash When copying files to a destination directory, the classic builder requires the destination to have a trailing slash (to indicate the target is a _directory_. not a filename). BuildKit is a bit more flexible in this, and will assume the target is a directory, but users following the example with buildkit disabled might see an error message, e.g.: Sending build context to Docker daemon 3.072kB Step 1/2 : FROM busybox ---> 69593048aa3a Step 2/2 : COPY *.go . When using COPY with more than one source file, the destination must be a directory and end with a / It doesn't hurt to be explicit, so this patch updates some examples to prevent this. Signed-off-by: Sebastiaan van Stijn --- .../dockerfile_best-practices.md | 8 +++---- develop/develop-images/multistage-build.md | 12 +++++----- language/golang/build-images.md | 22 +++++++++---------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/develop/develop-images/dockerfile_best-practices.md b/develop/develop-images/dockerfile_best-practices.md index 4010258e7e..fd78f89a53 100644 --- a/develop/develop-images/dockerfile_best-practices.md +++ b/develop/develop-images/dockerfile_best-practices.md @@ -170,13 +170,13 @@ context, refer to [exclude with .dockerignore](#exclude-with-dockerignore). > > docker build -t myimage:latest -< FROM busybox -> COPY somefile.txt . +> COPY somefile.txt ./ > RUN cat /somefile.txt > EOF > > # observe that the build fails > ... -> Step 2/3 : COPY somefile.txt . +> Step 2/3 : COPY somefile.txt ./ > COPY failed: stat /var/lib/docker/tmp/docker-builder249218248/somefile.txt: no such file or directory > ``` @@ -206,7 +206,7 @@ touch somefile.txt # build an image using the current directory as context, and a Dockerfile passed through stdin docker build -t myimage:latest -f- . <