GoogleContainerTools / GoogleContainerTools/skaffold
Dockerfile in .dockerignore is not respected, leading to unnecessary full rebuilds
- Dominant language
- Go
- Stars
- 15.9k
- Forks
- 1.7k
- Avg merge
- 3d 9h
- Merged PRs (30d)
- 10
Description
### Expected behavior
When I:
- have `Dockerfile` in `.dockerignore`
- use `COPY . .` in my `Dockerfile`
I expect the Dockerfile to NOT be copied into the image. This is indeed the behaviour when doing `docker build .`
### Actual behavior
`skaffold build` DOES copy the `Dockerfile` into the image, causing a lot of unnecessary build steps to be done every time anything (even just whitespace) changes in the `Dockerfile`
### Information
- Skaffold version: confirmed with v2.10.1 and v2.11.1
- Operating system: Ubuntu 23.10
- Installed via: asdf
- Contents of skaffold.yaml: https://github.com/GoogleContainerTools/skaffold/blob/v2.11.1/examples/getting-started/skaffold.yaml
- Dockerfile: https://github.com/GoogleContainerTools/skaffold/blob/v2.11.1/examples/getting-started/Dockerfile with one minor change: both `COPY` commands replaced with a single `COPY . .`:
```
FROM golang:1.18 as builder
WORKDIR /code
COPY . .
# `skaffold debug` sets SKAFFOLD_GO_GCFLAGS to disable compiler optimizations
ARG SKAFFOLD_GO_GCFLAGS
RUN go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -trimpath -o /app main.go
FROM alpine:3
# Define GOTRACEBACK to mark this container as using the Go language runtime
# for `skaffold debug` (https://skaffold.dev/docs/workflows/debug/).
ENV GOTRACEBACK=single
CMD ["./app"]
COPY --from=builder /app .
```
### Steps to reproduce the behavior
1. https://github.com/GoogleContainerTools/skaffold/blob/v2.11.1/examples/getting-started
2. replace both `COPY` commands in the `Dockerfile` with a single `COPY . .`
3. add a `.dockerignore` file containing just the line `Dockerfile`
4. `skaffold build`
5. Change anything at all in the `Dockerfile`, eg. adding an empty line
6. `skaffold build` now needs to recompile the binary rather than use the cached version
Note that `docker build` does NOT show this behaviour: it will correctly NOT copy the Dockerfile into the image, so it can reuse the cached image layers.
I am aware that `COPY . .` might not be the best practice, and changing the `Dockerfile` should be an infrequent occurence so this does not have any great impact. However, I do think it's worth to keep the behaviour of `skaffold build` as much the same as `docker build .` as possible.
Contributor guide
Assessment
This issue has not been assessed yet.