Go in Docker

Contents
The golang image
Run one-liners
Mount your module
Build inside the container

The golang image

The golang image ships a ready to use toolchain, so you can try Go without installing anything on the host.

Tags such as golang:1 follow the major release line, which keeps local experiments close to current stable builds.

Run one-liners

Ask the container for its Go version with a single disposable run.

docker run --rm golang:1 go version

go version go1.21 linux/amd64

The remove flag deletes the container after exit, while the image itself stays cached for the next run.

Mount your module

Mount the current project into the container and set it as the working directory for live runs.

docker run --rm -v "$PWD":/app -w /app golang:1 go run .

This command shares the host folder with the container, so edits on the host are visible to go run at once.

It is ideal for quick checks on machines where the native toolchain is not installed.

Build inside the container

Use the same image to compile a static binary, then copy the result out through the mounted folder.

Keep multi stage builds for production images, and use plain mounted builds while learning and testing ideas.

Next: Go course

Article author: Arthur Isaev

Related articles
Golang
Go course: zero to hero in 50 lessons
What is Go and where it runs
Install Go and check the version
Your first Go program
Modules with go mod
Variables
Constants
Types
Numbers
Strings
Conditions with if
Switch in Go
Loops with for
Arrays in Go
Slices in Go
Maps in Go
Functions in Go
Errors as values
Pointers in Go
Structs in Go
Methods in Go
Interfaces in Go
Embedding instead of inheritance
Generics in Go
Packages and imports
The go toolchain
Testing with go test
Advanced errors
defer in Go
Strings, bytes and runes
Time in Go
JSON
Files and IO
HTTP servers
HTTP clients
Context
Goroutines
Channels
select and sync
CLI: args, flags, env
Logging
Regular expressions
Sorting
Concurrency patterns
Databases with database/sql
Benchmarks and profiling
Toolchain and CI
Project layout
Capstone: wordfreq CLI
Capstone: JSON API server
Hero roadmap: the whole course on one page
Install Go on Windows 11
Install Go on Ubuntu
Install Go on Rocky Linux
Install Go on macOS
Install Go on FreeBSD
Go in Docker
Banner image

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: