
Creating and Running Go Containers in WSL2 with Podman
By David Maiden -
Modern software teams need fast, repeatable, and secure ways to build and ship applications. Creating and running Go containers in WSL2 using Podman provides a clean, developer-friendly workflow that also aligns with enterprise security and cost-efficiency goals. This guide explains how to containerize a Go application inside WSL2 using Podman.
Why Go, Containers, and WSL2 Are a Strong Combination
Go is known for producing small, fast, and reliable binaries. Containers make applications portable and consistent. WSL2 bridges Linux-native tooling with Windows-based development environments.
Together, they offer:
- Faster local development
- Production-like environments on developer machines
- Reduced “works on my machine” issues
- Lower infrastructure and security risks
For organizations, this means faster delivery with fewer surprises.
What WSL2 Brings to the Development Workflow
WSL2 runs a real Linux kernel inside Windows, not a compatibility layer. This makes it suitable for container-based development.
Key benefits include:
- Native Linux performance for containers
- Access to standard Linux tooling
- Seamless integration with Windows editors and IDEs
From an executive perspective, WSL2 reduces the need for separate Linux laptops or virtual machines while keeping teams productive.
Why Use Podman Instead of Docker in WSL2
Podman is a daemonless container engine designed with security in mind. It fits well into WSL2 environments.
Advantages of Podman include:
- No background daemon running as root
- Support for rootless containers by default
- Docker-compatible command structure
- Strong alignment with Kubernetes concepts
This makes Podman attractive to security teams while remaining familiar to developers.
High-Level Architecture Overview
Before diving into commands, it helps to understand what’s happening at a high level.
- Go compiles the application into a single binary
- A container image packages that binary
- Podman runs the container inside WSL2
- The application is exposed to the local system via networking
This mirrors how the application would run in staging or production.
Creating a Simple Go Application
Start with a minimal Go application. This example exposes a basic HTTP endpoint.
Create a file called main.go.
package main
import ( "fmt" "net/http" )
func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "Hello from a Go container running in WSL2") }
func main() { http.HandleFunc("/", handler) http.ListenAndServe(":8080", nil) }
This simplicity is intentional. Executives should note that Go applications often require fewer dependencies than other stacks, reducing container size and attack surface.
Building the Go Binary
Compile the application inside WSL2.
go build -o app
This produces a single binary named app. No runtime, no package manager, no extra dependencies.
For businesses, this translates to:
- Smaller images
- Faster startup times
- Lower operational complexity
Writing a Containerfile for the Go Application
Create a file named Containerfile.
FROM golang:1.22-alpine AS builder WORKDIR /app COPY . . RUN go build -o app
FROM alpine:latest WORKDIR /app COPY --from=builder /app/app . EXPOSE 8080 CMD ["./app"]
This is a multi-stage build:
- The first stage compiles the Go binary
- The second stage runs only the compiled binary
The result is a minimal, production-ready container image.
Building the Container Image with Podman
Build the image using Podman.
podman build -t go-wsl2-demo .
This command packages the application into a container image.
For developers, this step is repeatable and fast. For executives, this ensures consistency across environments.
Running the Go Container in WSL2
Run the container and expose the application.
podman run -p 8080:8080 go-wsl2-demo
Open a browser and navigate to http://localhost:8080.
You should see the message from the Go application.
At this point, the application is:
- Running in a container
- Isolated from the host system
- Accessible like a production service
Verifying and Managing the Running Container
List running containers.
podman ps
Stop the container when finished.
podman stop container_id
This lifecycle management mirrors what happens in CI/CD pipelines and production orchestration systems.
Security and Governance Considerations
From an executive standpoint, this workflow offers clear security advantages.
- Rootless containers reduce privilege escalation risks
- Smaller images reduce vulnerability exposure
- Clear separation between host and application
For regulated environments, this approach simplifies audits and compliance discussions.
How This Fits into CI/CD and Cloud Strategy
This local workflow maps cleanly to modern delivery pipelines.
- The same Containerfile can be used in CI
- Images can be pushed to private registries
- Containers can be deployed to Kubernetes or cloud platforms
This reduces rework and increases confidence during releases.
Common Pitfalls to Avoid
- Building images as root unnecessarily
- Using large base images
- Hardcoding environment-specific values
- Skipping container scanning in CI
Avoiding these issues early improves long-term maintainability.
When This Approach Makes the Most Sense
Creating and running Go containers in WSL2 is ideal when:
- Teams develop on Windows but deploy to Linux
- Security and consistency are priorities
- Organizations want faster onboarding for developers
- Leadership wants predictable, scalable delivery
Conclusion
Creating and running Go containers in WSL2 with Podman offers a practical, secure, and scalable development workflow. Developers benefit from speed and simplicity, while executives gain consistency, security, and reduced operational risk.
This approach aligns modern engineering practices with business goals, making it a strong foundation for teams building and shipping Go applications today.