You can see a full example of using Batect with Golang in the Golang sample project.
The Golang bundle provides a container with all of these options pre-configured.
tl;dr: Mount a cache into your container for your
GOCACHE, otherwise you'll have to download and compile your dependencies every
time the build runs
Golang caches the source for dependencies under
GOPATH. By default, this is at
However, because Batect destroys all of your containers once the task finishes, this directory is lost at the end of every task run - which means that Golang
will have to download all of your dependencies again next time you run the task, significantly slowing down the build.
The solution to this is to mount a cache into your container for your
GOPATH. This cache persists between task invocations, which
means that any downloaded dependencies will be available next time the task runs.
For example, the official Golang Docker images set
/go, so mounting a cache at
/go inside the container will
allow your dependencies to be persisted across builds.
The example configuration above demonstrates how to do this.
The Golang compiler caches intermediate build output (such as built libraries) in
Just like for
GOPATH, the contents of
GOCACHE will be lost when the task finishes and the container is removed, which means that Golang will have to recompile
all code for your project, even if it has not changed. This can also significantly slow down the build.
Again, the solution is to mount a cache into your container for your
The official Golang Docker images do not set a default for
GOCACHE, so you will need to set this yourself.
In the example above,
GOCACHE has been placed inside
/go (which is the default
GOPATH) so that both use the same cache.
tl;dr: Mount a cache into your container at
~/.cache/golangci-lint/, otherwise you'll experience slow performance from
golangci-lint caches build artifacts used during analysis to speed up subsequent runs.
By default, it stores this cache at
Without a mounted cache, this directory would be lost every time Batect starts a new container, causing
golangci-lint to need to rebuild your application
every time you run it.
The solution to this is to mount a cache into your container for
For example, assuming the home directory for your container's user is