Merge pull request #13208 from thaJeztah/fix_copy_examples

Fix Dockerfile COPY/ADD examples without a trailing slash
This commit is contained in:
Usha Mandya 2021-07-21 11:17:59 +01:00 committed by GitHub
commit 3afec9c587
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 21 deletions

View File

@ -170,13 +170,13 @@ context, refer to [exclude with .dockerignore](#exclude-with-dockerignore).
>
> docker build -t myimage:latest -<<EOF
> 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- . <<EOF
FROM busybox
COPY somefile.txt .
COPY somefile.txt ./
RUN cat /somefile.txt
EOF
```
@ -232,7 +232,7 @@ the `hello.c` file from the ["hello-world" Git repository on GitHub](https://git
```bash
docker build -t myimage:latest -f- https://github.com/docker-library/hello-world.git <<EOF
FROM busybox
COPY hello.c .
COPY hello.c ./
EOF
```

View File

@ -40,7 +40,7 @@ builder pattern above:
# syntax=docker/dockerfile:1
FROM golang:1.16
WORKDIR /go/src/github.com/alexellis/href-counter/
COPY app.go .
COPY app.go ./
RUN go get -d -v golang.org/x/net/html \
&& CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
```
@ -57,7 +57,7 @@ and forget to continue the line using the `\` character, for example.
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY app .
COPY app ./
CMD ["./app"]
```
@ -103,13 +103,13 @@ multi-stage builds.
FROM golang:1.16
WORKDIR /go/src/github.com/alexellis/href-counter/
RUN go get -d -v golang.org/x/net/html
COPY app.go .
COPY app.go ./
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=0 /go/src/github.com/alexellis/href-counter/app .
COPY --from=0 /go/src/github.com/alexellis/href-counter/app ./
CMD ["./app"]
```
@ -143,13 +143,13 @@ Dockerfile are re-ordered later, the `COPY` doesn't break.
FROM golang:1.16 AS builder
WORKDIR /go/src/github.com/alexellis/href-counter/
RUN go get -d -v golang.org/x/net/html
COPY app.go .
COPY app.go ./
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /go/src/github.com/alexellis/href-counter/app .
COPY --from=builder /go/src/github.com/alexellis/href-counter/app ./
CMD ["./app"]
```

View File

@ -152,8 +152,8 @@ In its simplest form, the `COPY` command takes two parameters. The first paramet
Well copy the `go.mod` and `go.sum` file into our working directory `/app` which, owing to our use of `WORKDIR`, is the current directory (`.`) inside the image.
```dockerfile
COPY go.mod .
COPY go.sum .
COPY go.mod ./
COPY go.sum ./
```
Now that we have the module files inside the Docker image that we are building, we can use the `RUN` command to execute the command `go mod download` there as well. This works exactly the same as if we were running `go` locally on our machine, but this time these Go modules will be installed into the a directory inside our image.
@ -167,7 +167,7 @@ At this point, we have an image that is based on Go environment version 1.16 (or
The next thing we need to do is to copy our source code into the image. Well use the `COPY` command just like we did with our module files before.
```dockerfile
COPY *.go .
COPY *.go ./
```
This `COPY` command uses a wildcard to copy all files with `.go` extension located in the current directory on the host (the directory where the `Dockerfile` is located) into the current directory inside the image.
@ -195,11 +195,11 @@ FROM golang:1.16-alpine
WORKDIR /app
COPY go.mod .
COPY go.sum .
COPY go.mod ./
COPY go.sum ./
RUN go mod download
COPY *.go .
COPY *.go ./
RUN go build -o /docker-gs-ping
@ -218,8 +218,8 @@ FROM golang:1.16-alpine
WORKDIR /app
# Download necessary Go modules
COPY go.mod .
COPY go.sum .
COPY go.mod ./
COPY go.sum ./
RUN go mod download
# ... the rest of the Dockerfile is ...
@ -351,11 +351,11 @@ FROM golang:1.16-buster AS build
WORKDIR /app
COPY go.mod .
COPY go.sum .
COPY go.mod ./
COPY go.sum ./
RUN go mod download
COPY *.go .
COPY *.go ./
RUN go build -o /docker-gs-ping