- 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.
sudo dnf update -y
sudo dnf install -y docker
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
newgrp docker
docker version # verify
Two main sources:
-
Stable releases (safe for production)
-
Hosted at hub.docker.com/_/swift
-
Example:
docker pull swift:6.1.2-jammy-slim
-
-
Nightlies / unreleased versions (e.g. Swift 6.2)
-
Hosted at hub.docker.com/r/swiftlang/swift
-
Example:
docker pull swiftlang/swift:nightly-6.2-jammy
-
docker run --rm -it swift:6.1.2-jammy swift --version
(or swap in swiftlang/swift:nightly-6.2-jammy
)
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 ...
.
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
For production, push the image to Amazon ECR, then pull/run it on EC2 or ECS/Fargate.
- Use Docker to sidestep missing Swift support on AL2023.
- Pick
swift:<version>-jammy
for stable, orswiftlang/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.