Blue cartoon gopher, the Golang mascot, with a mustache, wearing a yellow hat, and holding a walking stickGophersLand where Gophers go to land

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 -goroot flag to direct godoc to your source root instead of defaulting to $GOPATH.

    godoc -http=:6060 -goroot ~/my/go/projects
    
  • To enable fast full-text search throughout your codebase, add the -index flag:

    godoc -http=:6060 -index
    
  • Consider launching godoc in 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.target
    

    And remember to replace /usr/local/go with your $GOPATH. Then enable and start the service:

    systemctl daemon-reload && systemctl enable --now godoc
    
  • If you use a local LLM-based AI agent, you may give it access to Go documentation using godoc-mcp.