skip to Main Content

I’m doing go development.
Sometimes when I do docker build it doesn’t build. It’s pretty obvious by the output, since the build process has to download some libs into the container.
What can I put in my Dockerfile to force it to always build?
This is one of the Dockerfiles that does this sometimes, with some minor employer stuff sanitized:

FROM golang:1.17 AS build

WORKDIR /software

COPY . ./

# Without this, the resultant binary expects some DNS resolver
# files that are actually optional, and (obviously) don't
# exist on scratch
ENV CGO_ENABLED=0

RUN go build

FROM scratch

COPY --from=build /program /program

EXPOSE 8000/tcp

ENTRYPOINT [ "/program" ]

2

Answers


  1. Docker build will only re-build where there is a change in your Dockerfile.

    It will cache what it has built that has not changed so it does not have to do it again later.

    You can use --no-cache to force this, but I wouldn’t do this every build as just wastes time, effort, and computing power.


    Here are the official docs to this feature: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#leverage-build-cache

    Login or Signup to reply.
  2. can use
    docker build --no-cache

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search