docs icon indicating copy to clipboard operation
docs copied to clipboard

docs: use bind mounts in Go Dockerfile examples

Open Juneezee opened this issue 8 months ago • 3 comments

Description

I remembered there used to be a page (https://docs.docker.com/build/guide/mounts/) that demonstrated how to use both bind mounts and cache mounts together in a Dockerfile for a Go application. However, that page was removed in https://github.com/docker/docs/pull/20715, and the new page (https://docs.docker.com/build/cache/optimize/) now separates the examples for bind mounts and cache mounts.

https://github.com/docker/docs/blob/91b324fb4dfd31ff5a0f6a8bd55f1c667619ca2b/content/build/guide/mounts.md?plain=1#L185-L194

It would be great if the remaining Go Dockerfile examples could show how to use both bind mounts and cache mounts together ~~specifically for go.mod and go.sum. This combination was really helpful for improving build performance and clarity when using Docker for Go development.~~ (See https://github.com/docker/docs/pull/22388#issuecomment-2795683162 for updtae)

Related issues or tickets

  • https://github.com/docker/docs/pull/20715

Reviews

  • [ ] Technical review
  • [ ] Editorial review
  • [ ] Product review

Juneezee avatar Apr 08 '25 15:04 Juneezee

Deploy Preview for docsdocker ready!

Name Link
Latest commit 0ddf9cf9bbbb619521759196701c63fcfe6d40e4
Latest deploy log https://app.netlify.com/projects/docsdocker/deploys/693179c474ff970008240a8c
Deploy Preview https://deploy-preview-22388--docsdocker.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

netlify[bot] avatar Apr 08 '25 15:04 netlify[bot]

UPDATE: I have removed the go mod download step in commit cf728b44d9dc054e3b042b6a948f962888d06855.

go build will automatically download module dependencies. In many cases, that is a much smaller set of modules than what is downloaded by go mod download. I found a great explanation on StackOverflow here: https://stackoverflow.com/a/68172023/7902371

Using the https://github.com/github/github-mcp-server Go application as an example below.

Size of GOMODCACHE with go mod download:

~/Desktop/github/github-mcp-server docker ❯ go clean -i -r -cache -modcache

~/Desktop/github/github-mcp-server docker ❯ go mod download

~/Desktop/github/github-mcp-server docker ❯ du -sh ~/go/pkg/mod
186M	/home/jun/go/pkg/mod

Size of GOMODCACHE with go build:

~/Desktop/github/github-mcp-server docker !1 ❯ go clean -i -r -cache -modcache

~/Desktop/github/github-mcp-server docker !1 ❯ CGO_ENABLED=0 go build -ldflags="-s -w" cmd/github-mcp-server/main.go
go: downloading github.com/spf13/viper v1.20.1
go: downloading github.com/mark3labs/mcp-go v0.18.0
go: downloading github.com/google/go-github/v69 v69.2.0
go: downloading github.com/sirupsen/logrus v1.9.3
go: downloading github.com/spf13/cobra v1.9.1
go: downloading golang.org/x/sys v0.31.0
go: downloading github.com/spf13/afero v1.14.0
go: downloading github.com/fsnotify/fsnotify v1.8.0
go: downloading github.com/spf13/cast v1.7.1
go: downloading github.com/go-viper/mapstructure/v2 v2.2.1
go: downloading github.com/subosito/gotenv v1.6.0
go: downloading gopkg.in/yaml.v3 v3.0.1
go: downloading github.com/spf13/pflag v1.0.6
go: downloading github.com/pelletier/go-toml/v2 v2.2.3
go: downloading github.com/sagikazarmark/locafero v0.9.0
go: downloading golang.org/x/text v0.23.0
go: downloading github.com/google/uuid v1.6.0
go: downloading github.com/yosida95/uritemplate/v3 v3.0.2
go: downloading github.com/sourcegraph/conc v0.3.0
go: downloading github.com/google/go-querystring v1.1.0

~/Desktop/github/github-mcp-server docker !1 ?1 ❯ du -sh ~/go/pkg/mod
80M	/home/jun/go/pkg/mod

Running go build results in a smaller GOMODCACHE (~80 MB) compared to go mod download (~186 MB).

Juneezee avatar Apr 11 '25 02:04 Juneezee

Hi @aevesdocker @crazy-max, when you have a moment, could you take a quick look at this PR and let me know if it would be a worthwhile improvement to the documentation?

Thanks :blush:

Juneezee avatar May 13 '25 10:05 Juneezee

Hi @thaJeztah and @crazy-max,

It's been a while. I wanted to follow up on this PR since I addressed the previous review comments.

Is there anything else I should do from my side, or do you think the PR is ready for the next review round/merge?

Thank you!

/cc @dvdksn (Author of PR #20715)

Juneezee avatar Dec 03 '25 04:12 Juneezee