Skip to content

swag fmt fails in Docker image: "go command required, not found" #2088

@Gustik

Description

@Gustik

Description

The official Docker image ghcr.io/swaggo/swag:latest cannot execute swag fmt command because the Go binary is not available inside the container.

Steps to Reproduce

  1. Pull the latest Docker image:
   docker pull ghcr.io/swaggo/swag:latest
  1. Try to run swag fmt:
   docker run --rm -v $(pwd):/code ghcr.io/swaggo/swag:latest fmt

Expected Behavior

The swag fmt command should format Swagger comments in Go files.

Actual Behavior

2025/10/29 12:30:23 fmt: err: go command required, not found: exec: "go": executable file not found in $PATH: stderr:

Environment

  • Docker image: ghcr.io/swaggo/swag:latest
  • Image digest: sha256:03c4d91c721789d904615a48b5c8d574c5ad90f11de39a783c368d4867533c4b
  • Host OS: macOS / Linux
  • Docker version: Docker version 24.x

Additional Context

The swag init command works fine in the same image, only swag fmt fails because it requires the Go toolchain.

Possible Solutions

  1. Include Go binary in the Docker image (similar to how other tools like golangci-lint do it)
  2. Document this limitation in README with workarounds
  3. Provide separate images: swag:latest (init only) and swag:full (with Go for fmt)

Workaround

Currently, users need to either:

  • Use local gofmt instead of swag fmt
  • Mount local Go binary into the container (complex setup)
  • Build a custom image with Go included

Related

This affects CI/CD pipelines where users want to run both fmt and init in Docker without installing local dependencies.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions