clang

Provides the Clang C, C++, and Objective-C compiler frontend based on LLVM for building and analyzing native code in a container environment.

gcc, llvm, emscripten, musl-cross

What is clang?

The clang image packages the Clang compiler, part of the LLVM project, for compiling C, C++, and Objective-C source code. Clang is widely used as an alternative to GCC due to its fast compilation times, expressive diagnostics, and tight integration with LLVM's optimization and analysis toolchain. It also powers static analysis tools such as clang-tidy and clang-analyzer.

The containerized image is used in CI/CD pipelines for cross-platform builds, in security toolchains for static analysis, and in development environments where a reproducible, version-pinned compiler is needed without modifying the host system.

How to use this image

Compile a single C file:

docker run --rm \
  -v $(pwd):/src -w /src \
  silkeh/clang \
  clang -o hello hello.c

Compile a C++ project:

docker run --rm \
  -v $(pwd):/src -w /src \
  silkeh/clang \
  clang++ -std=c++17 -O2 -o app main.cpp

Run clang-tidy for static analysis:

docker run --rm \
  -v $(pwd):/src -w /src \
  silkeh/clang \
  clang-tidy main.cpp -- -std=c++17

Use in a multi-stage Dockerfile:

FROM silkeh/clang AS builder
WORKDIR /src
COPY . .
RUN clang++ -std=c++17 -O2 -static -o app main.cpp

FROM scratch
COPY --from=builder /src/app /app
ENTRYPOINT ["/app"]

Image variants

silkeh/clang:latest

The most recent stable Clang release. Based on Debian. Includes Clang, clang++, clang-tidy, clang-format, and related LLVM tools.

silkeh/clang:<version>

Pinned major version tags such as silkeh/clang:16 or silkeh/clang:17. Use to align the compiler version with your project's toolchain requirements.

Interested in base images that start and stay clean?