How does one add Swift to an existing Docker image?

I need to add Swift to an existing CentOS 7 Docker image. I'm 100% new to Docker. How can I do this?

I perused the documentation here: https://hub.docker.com/_/swift

However it does not give a step-by-step guide on how to add Swift to an existing Docker image. That page provides links to Apple's Swift Docker images, but it's not made clear how one would add Swift to a different Docker image than the ones shown here.

Why I need to do this:

Our existing CentOS 7 Docker image builds a server that runs on one of our CI nodes. Currently this server is responsible for building Java and TypeScript objects from protobuf objects. I need to add to this support to also build Swift protobuf objects, which we will then export to a git repo.

Things I've Already Tried that Failed

I tried copy-pasting the commands from Apple's existing CentOS 8 Swift Docker image into my image, but it fails on the last step:

Step 25/25 : RUN swift --version
 ---> Running in 75fa04b6c4cb
swift: error while loading shared libraries: libtinfo.so.6: cannot open shared object file: No such file or directory

I also tried adding "libtinfo" to the list of things to "yum install" however we don't seem to have it on our CentOS 7 yum repo.

I also tried simply adding this to the end of my existing docker file:

FROM swift:latest as builder
WORKDIR /root
COPY . .
RUN swift build -c release

However I was unable to use "builder" since there's already a "builder" earlier in the Docker image (which is used for adding the TypeScript protobuf generator).

I changed "builder" to "builder2", but then RUN swift build -c release errors out, with "error: root manifest not found".

Any tips would be appreciated, thank you!

Combining docker images was not a straightforward task last time I tried. You could instead copy the contents of this PR

The Battle of Chosin Reservoir comes to mind. Or getting Mono to support OpenGL and sound on a 2006 PowerBook G4.

Thanks @masters3d! Problem I'm running into now is the fact that my company requires us to use certain internal yum repos for everything, and they don't seem to have half the dependencies that Swift needs.

It would be awfully nice if there was an installer for Swift that provides all the dependencies it needs to run, rather than requiring you to install all these dependency libs.

So I noticed that there is now an official Apple docker image for "swift-ci" on CentOS 7:

However... this is not the same as the main Swift docker images. Still there is no CentOS 7 docker image for Swift itself.

Curious what we can do to make that happen?

Unless you’re asking what remaining problems are being solved before officially releasing a CentOS 7 Docker image, the only thing to do is wait for Apple to determine that the image they are currently prepping or using for CI is ready for general consumption.

Apple has already stated that this image is (almost certainly) going to be added for official support:

Our plan is to continue and grow the number of Linux distributions we support, with CentOS 7, Debian and Fedora the most likely candidates to be added next.

I have been trying to build Swift locally in Docker using Apple's Swift "CI" image for CentOS 7 as the basis, but it errors out during compilation.

Going to paste the log below. If you have any tips it would be appreciated.

The commands I used for the build are as follows:

RUN source /opt/rh/sclo-git25/enable; \
    source /opt/rh/llvm-toolset-7/enable; \
    source /opt/rh/devtoolset-8/enable; \
    mkdir swift_source; cd swift_source; \
    git clone --depth 1 --branch swift-5.2.4-RELEASE https://github.com/apple/swift/;\
    ./swift/utils/update-checkout --clone --tag swift-5.2.4-RELEASE

# Keep the following as a separate command so if it fails we don't have to redo the checkout of Swift on the prior step in the next build. 

RUN source /opt/rh/sclo-git25/enable; \
    source /opt/rh/llvm-toolset-7/enable; \
    source /opt/rh/devtoolset-8/enable; \
    cd /swift_source/swift; \
    utils/build-script --reconfigure --release-debuginfo --install-swiftpm true -j8

Here is the failure log:

[488/3589][ 13%][599.111s] Building CXX object lib/CodeGen/SelectionDAG/CMakeFiles/LLVMSelectionDAG.dir/StatepointLowering.cpp.o
[488/3589][ 13%][599.117s] Building CXX object lib/CodeGen/AsmPrinter/CMakeFiles/LLVMAsmPrinter.dir/ARMException.cpp.o
[489/3589][ 13%][607.758s] Building CXX object lib/CodeGen/AsmPrinter/CMakeFiles/LLVMAsmPrinter.dir/AddressPool.cpp.o
[489/3589][ 13%][607.762s] Building CXX object lib/CodeGen/AsmPrinter/CMakeFiles/LLVMAsmPrinter.dir/DIEHash.cpp.o
[490/3589][ 13%][607.941s] Building CXX object lib/CodeGen/SelectionDAG/CMakeFiles/LLVMSelectionDAG.dir/DAGCombiner.cpp.o
FAILED: lib/CodeGen/SelectionDAG/CMakeFiles/LLVMSelectionDAG.dir/DAGCombiner.cpp.o 
/opt/rh/llvm-toolset-7/root/usr/bin/clang++  -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib/CodeGen/SelectionDAG -I/swift/llvm-project/llvm/lib/CodeGen/SelectionDAG -I/usr/include/libxml2 -Iinclude -I/swift/llvm-project/llvm/include -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector -g -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -std=c++14 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wcovered-switch-default -Wno-class-memaccess -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color -ffunction-sections -fdata-sections -O2    -UNDEBUG -gsplit-dwarf  -fno-exceptions -fno-rtti -MD -MT lib/CodeGen/SelectionDAG/CMakeFiles/LLVMSelectionDAG.dir/DAGCombiner.cpp.o -MF lib/CodeGen/SelectionDAG/CMakeFiles/LLVMSelectionDAG.dir/DAGCombiner.cpp.o.d -o lib/CodeGen/SelectionDAG/CMakeFiles/LLVMSelectionDAG.dir/DAGCombiner.cpp.o -c /swift/llvm-project/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
clang-5.0: error: unable to execute command: Killed
clang-5.0: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 5.0.1 (tags/RELEASE_501/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/rh/llvm-toolset-7/root/usr/bin
clang-5.0: note: diagnostic msg: PLEASE submit a bug report to  and include the crash backtrace, preprocessed source, and associated run script.
clang-5.0: note: diagnostic msg: 
********************

This would indicate that clang gets killed. Is it possible that your container is running out of memory and the OOM killer kicks in?

This would indicate that clang gets killed. Is it possible that your container is running out of memory and the OOM killer kicks in?

Yeah I think this was happening. I've increased it to use 12 GB of RAM instead of 4 GB, and that seems to have done the trick. Now I'm dealing with other issues though. SwiftPM build keeps erroring out.

The fix for that was just merged into the SPM 5.2 branch. If you try again now it should work.

Terms of Service

Privacy Policy

Cookie Policy