Running a `godoc` server locally
Install and run godoc
Install it by running
go install golang.org/x/tools/cmd/godoc@latest
then launch it
godoc -http=:6060
and visit http://localhost:6060 to access documentation for all Go packages in your environment.
Run with Docker
You may also run godoc inside a Docker container as follows:
docker run --rm -p 6060:6060 golang:latest sh -c "go install golang.org/x/tools/cmd/godoc@latest && godoc -http=:6060"
To gain access to documentation for your local Go code, simply bind-mount the relevant directories into the container. It is perfectly sufficient to mount them read-only.
Miscellaneous Tips
Use the
-gorootflag to directgodocto your source root instead of defaulting to$GOPATH.godoc -http=:6060 -goroot ~/my/go/projectsTo enable fast full-text search throughout your codebase, add the
-indexflag:godoc -http=:6060 -indexConsider launching
godocin the background at startup, e.g. as a systemd service like this:/etc/systemd/system/godoc.service[Unit] Description=Godoc Service [Service] ExecStart=/usr/local/go/bin/godoc -http=:6060 [Install] WantedBy=multi-user.targetAnd remember to replace
/usr/local/gowith your$GOPATH. Then enable and start the service:systemctl daemon-reload && systemctl enable --now godocIf you use a local LLM-based AI agent, you may give it access to Go documentation using godoc-mcp.