develop: Update multi-stage example to use go mod (#17829)

Signed-off-by: Chris Crone <christopher.crone@docker.com>
This commit is contained in:
Chris Crone 2023-07-26 19:14:47 -04:00 committed by GitHub
parent 999de0ae4f
commit 0b663956f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 5 deletions

View File

@ -237,19 +237,18 @@ A Dockerfile for a Go application could look like:
```dockerfile ```dockerfile
# syntax=docker/dockerfile:1 # syntax=docker/dockerfile:1
FROM golang:1.16-alpine AS build FROM golang:{{site.example_go_version}}-alpine AS build
# Install tools required for project # Install tools required for project
# Run `docker build --no-cache .` to update dependencies # Run `docker build --no-cache .` to update dependencies
RUN apk add --no-cache git RUN apk add --no-cache git
RUN go get github.com/golang/dep/cmd/dep
# List project dependencies with Gopkg.toml and Gopkg.lock # List project dependencies with go.mod and go.sum
# These layers are only re-built when Gopkg files are updated # These layers are only re-built when Gopkg files are updated
COPY Gopkg.lock Gopkg.toml /go/src/project/
WORKDIR /go/src/project/ WORKDIR /go/src/project/
COPY go.mod go.sum /go/src/project/
# Install library dependencies # Install library dependencies
RUN dep ensure -vendor-only RUN go mod download
# Copy the entire project and build it # Copy the entire project and build it
# This layer is rebuilt when a file changes in the project directory # This layer is rebuilt when a file changes in the project directory