Currently, the Swift Docker images come "batteries included", with everything users need to build and run Swift programs, run the REPL etc. This means that they are necessarily quite large.
Other languages also offer "slim" images, which are images that only contain what's required to run a program. For example, in the case of Java this means the slim image includes the JVM but not the Java compiler. For Node.js it includes the runtime but not
I would like us to publish slim images for Swift as well and I have prototyped what such images would look like. There would be two main differences from the current images.
- The system package requirements would be much lighter, just:
libatomic1 libbsd0 libcurl4 libxml2 tzdataI think.
- We would not include the entire Swift toolchain, just the
/usr/lib/swift/linuxshared libraries from the tar.gz.
Taking this approach, my slim image is ~250MB, in comparison to 1.37GB for the full image.
One nice thing about this is it means users can use a multi-stage
Dockerfile to build their app, something like this:
FROM swift:5.0 as builder WORKDIR /root COPY . . RUN swift build FROM swift:5.0-slim WORKDIR /root COPY --from=builder /root . CMD [".build/x86_64-unknown-linux/debug/docker-test"]
What do people think about this?