Skip to content

Instantly share code, notes, and snippets.

@brennanMKE
Created September 10, 2025 20:46
Show Gist options
  • Save brennanMKE/053a27759299b9374ee71ce32ae912ec to your computer and use it in GitHub Desktop.
Save brennanMKE/053a27759299b9374ee71ce32ae912ec to your computer and use it in GitHub Desktop.
Swift on AL2023 using Docker

πŸš€ Why Docker for Swift on AL2023?

  • AL2023 has no official Swift toolchain β†’ library mismatches, no RPM packages.
  • Docker solves this by running Swift in a compatible Ubuntu userland (or nightly images) while still using the host’s Linux kernel.
  • Overhead is tiny β†’ CPU/memory nearly native, only extra disk space for images.

πŸ›  Step 1: Install Docker on AL2023

sudo dnf update -y
sudo dnf install -y docker
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
newgrp docker
docker version   # verify

πŸ›  Step 2: Choose a Swift Docker image

Two main sources:

  1. Stable releases (safe for production)

  2. Nightlies / unreleased versions (e.g. Swift 6.2)


πŸ›  Step 3: Run Swift interactively

docker run --rm -it swift:6.1.2-jammy swift --version

(or swap in swiftlang/swift:nightly-6.2-jammy)


πŸ›  Step 4: Develop with your source code

Mount your project into the container:

mkdir ~/swift-app && cd ~/swift-app

docker run --rm -it -v "$PWD":/app -w /app swift:6.1.2-jammy \
  bash -lc 'swift package init --type executable && swift build && swift test'

Build/run repeatedly by re-invoking docker run ....


πŸ›  Step 5: Package for deployment (multi-stage Dockerfile)

Example Dockerfile:

# --- Build stage ---
FROM swift:6.1.2-jammy AS builder
WORKDIR /build
COPY . .
RUN swift build -c release

# --- Runtime stage ---
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y --no-install-recommends \
    libicu70 libxml2 libbsd0 zlib1g tzdata ca-certificates && \
    rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=builder /build/.build/release/YourTarget /usr/local/bin/app
EXPOSE 8080
CMD ["/usr/local/bin/app"]

Build & run:

docker build -t my-swift-app .
docker run --rm -p 8080:8080 my-swift-app

πŸ›  Step 6: (Optional) Push to ECR

For production, push the image to Amazon ECR, then pull/run it on EC2 or ECS/Fargate.


βœ… Key Takeaways

  • Use Docker to sidestep missing Swift support on AL2023.
  • Pick swift:<version>-jammy for stable, or swiftlang/swift:nightly-6.2-* for bleeding edge.
  • Overhead is negligible compared to native execution.
  • Develop by mounting code into containers, deploy with a multi-stage Dockerfile.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment