Skip to content

Commit d9578ae

Browse files
committed
refactor(container): reduce layers and image size
- Combines the RUN commands to reduce image layers where possible. - Clean apt/dnf package cache and remove downloaded package files.
1 parent 032361a commit d9578ae

File tree

4 files changed

+64
-59
lines changed

4 files changed

+64
-59
lines changed

container/rockylinux9-cuda12/Dockerfile

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ RUN dnf -y install \
77
redhat-rpm-config \
88
which \
99
xz \
10-
zlib-devel
10+
zlib-devel && \
11+
dnf clean all
1112

1213
# Needed to build `path_tracer`, `optix/ex03_window` example
1314
RUN dnf -y install \
@@ -16,30 +17,31 @@ RUN dnf -y install \
1617
libX11-devel \
1718
libXcursor-devel \
1819
libXi-devel \
19-
libXrandr-devel
20+
libXrandr-devel && \
21+
dnf clean all
2022

2123
# Get LLVM 7 & libffi.so.6
2224
WORKDIR /data/llvm7
23-
RUN curl -sSf -L -O https://dl.fedoraproject.org/pub/epel/9/Everything/x86_64/Packages/l/libffi3.1-3.1-36.el9.x86_64.rpm
24-
RUN curl -sSf -L -O https://dl.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/l/llvm7.0-7.0.1-7.el8.x86_64.rpm
25-
RUN curl -sSf -L -O https://dl.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/l/llvm7.0-devel-7.0.1-7.el8.x86_64.rpm
26-
RUN curl -sSf -L -O https://dl.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/l/llvm7.0-libs-7.0.1-7.el8.x86_64.rpm
27-
RUN curl -sSf -L -O https://dl.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/l/llvm7.0-static-7.0.1-7.el8.x86_64.rpm
28-
RUN dnf -y install ./*.rpm
29-
RUN ln -s /usr/bin/llvm-config-7-64 /usr/bin/llvm-config
25+
RUN curl -sSf -L -O https://dl.fedoraproject.org/pub/epel/9/Everything/x86_64/Packages/l/libffi3.1-3.1-36.el9.x86_64.rpm && \
26+
curl -sSf -L -O https://dl.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/l/llvm7.0-7.0.1-7.el8.x86_64.rpm && \
27+
curl -sSf -L -O https://dl.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/l/llvm7.0-devel-7.0.1-7.el8.x86_64.rpm && \
28+
curl -sSf -L -O https://dl.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/l/llvm7.0-libs-7.0.1-7.el8.x86_64.rpm && \
29+
curl -sSf -L -O https://dl.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/l/llvm7.0-static-7.0.1-7.el8.x86_64.rpm && \
30+
dnf -y install ./*.rpm && \
31+
ln -s /usr/bin/llvm-config-7-64 /usr/bin/llvm-config && \
32+
rm -rf ./*.rpm && \
33+
dnf clean all
3034

3135
# Get Rust
3236
RUN curl -sSf -L https://sh.rustup.rs | bash -s -- -y
3337
ENV PATH="/root/.cargo/bin:${PATH}"
3438

3539
# Setup the workspace
36-
ADD ./rust-toolchain.toml /data/Rust-CUDA/
3740
WORKDIR /data/Rust-CUDA
38-
RUN rustup show
39-
RUN rm -f "rust-toolchain.toml"
41+
RUN --mount=type=bind,source=rust-toolchain.toml,target=/data/Rust-CUDA/rust-toolchain.toml \
42+
rustup show
4043

4144
# Add nvvm to LD_LIBRARY_PATH.
4245
ENV LD_LIBRARY_PATH="/usr/local/cuda/nvvm/lib64:${LD_LIBRARY_PATH}"
43-
4446
ENV LLVM_LINK_STATIC=1
4547
ENV RUST_LOG=info

container/ubuntu22-cuda11/Dockerfile

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
11
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04
22

3-
RUN apt-get update
4-
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
3+
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
54
build-essential \
65
curl \
76
clang \
87
libssl-dev \
98
libtinfo-dev \
109
pkg-config \
1110
xz-utils \
12-
zlib1g-dev
11+
zlib1g-dev && \
12+
rm -rf /var/lib/apt/lists/*
1313

1414
# Needed to build `path_tracer`, `optix/ex03_window` example
15-
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
15+
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
1616
cmake \
1717
libfontconfig-dev \
1818
libx11-xcb-dev \
1919
libxcursor-dev \
2020
libxi-dev \
2121
libxinerama-dev \
22-
libxrandr-dev
22+
libxrandr-dev && \
23+
rm -rf /var/lib/apt/lists/*
2324

2425
# Get LLVM 7
2526
WORKDIR /data/llvm7
26-
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7_7.0.1-12_amd64.deb
27-
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-dev_7.0.1-12_amd64.deb
28-
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/libllvm7_7.0.1-12_amd64.deb
29-
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-runtime_7.0.1-12_amd64.deb
30-
RUN apt-get install -y ./*.deb
31-
RUN ln -s /usr/bin/llvm-config-7 /usr/bin/llvm-config
27+
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7_7.0.1-12_amd64.deb && \
28+
curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-dev_7.0.1-12_amd64.deb && \
29+
curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/libllvm7_7.0.1-12_amd64.deb && \
30+
curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-runtime_7.0.1-12_amd64.deb && \
31+
apt-get update && apt-get install -y ./*.deb && \
32+
ln -s /usr/bin/llvm-config-7 /usr/bin/llvm-config && \
33+
rm -rf ./*.deb && \
34+
rm -rf /var/lib/apt/lists/*
3235

3336
# Get Rust
3437
RUN curl -sSf -L https://sh.rustup.rs | bash -s -- -y
3538
ENV PATH="/root/.cargo/bin:${PATH}"
3639

3740
# Setup the workspace
38-
ADD ./rust-toolchain.toml /data/Rust-CUDA/
3941
WORKDIR /data/Rust-CUDA
40-
RUN rustup show
41-
RUN rm -f "rust-toolchain.toml"
42+
RUN --mount=type=bind,source=rust-toolchain.toml,target=/data/Rust-CUDA/rust-toolchain.toml \
43+
rustup show
4244

4345
# Add nvvm to LD_LIBRARY_PATH.
4446
ENV LD_LIBRARY_PATH="/usr/local/cuda/nvvm/lib64:${LD_LIBRARY_PATH}"
45-
4647
ENV LLVM_LINK_STATIC=1
4748
ENV RUST_LOG=info

container/ubuntu22-cuda12/Dockerfile

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
11
FROM nvidia/cuda:12.8.1-cudnn-devel-ubuntu22.04
22

3-
RUN apt-get update
4-
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
3+
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
54
build-essential \
65
curl \
76
clang \
87
libssl-dev \
98
libtinfo-dev \
109
pkg-config \
1110
xz-utils \
12-
zlib1g-dev
11+
zlib1g-dev && \
12+
rm -rf /var/lib/apt/lists/*
1313

1414
# Needed to build `path_tracer`, `optix/ex03_window` example
15-
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
15+
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
1616
cmake \
1717
libfontconfig-dev \
1818
libx11-xcb-dev \
1919
libxcursor-dev \
2020
libxi-dev \
2121
libxinerama-dev \
22-
libxrandr-dev
22+
libxrandr-dev && \
23+
rm -rf /var/lib/apt/lists/*
2324

2425
# Get LLVM 7
2526
WORKDIR /data/llvm7
26-
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7_7.0.1-12_amd64.deb
27-
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-dev_7.0.1-12_amd64.deb
28-
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/libllvm7_7.0.1-12_amd64.deb
29-
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-runtime_7.0.1-12_amd64.deb
30-
RUN apt-get install -y ./*.deb
31-
RUN ln -s /usr/bin/llvm-config-7 /usr/bin/llvm-config
27+
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7_7.0.1-12_amd64.deb && \
28+
curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-dev_7.0.1-12_amd64.deb && \
29+
curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/libllvm7_7.0.1-12_amd64.deb && \
30+
curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-runtime_7.0.1-12_amd64.deb && \
31+
apt-get update && apt-get install -y ./*.deb && \
32+
ln -s /usr/bin/llvm-config-7 /usr/bin/llvm-config && \
33+
rm -rf ./*.deb && \
34+
rm -rf /var/lib/apt/lists/*
3235

3336
# Get Rust
3437
RUN curl -sSf -L https://sh.rustup.rs | bash -s -- -y
3538
ENV PATH="/root/.cargo/bin:${PATH}"
3639

3740
# Setup the workspace
38-
ADD ./rust-toolchain.toml /data/Rust-CUDA/
3941
WORKDIR /data/Rust-CUDA
40-
RUN rustup show
41-
RUN rm -f "rust-toolchain.toml"
42+
RUN --mount=type=bind,source=rust-toolchain.toml,target=/data/Rust-CUDA/rust-toolchain.toml \
43+
rustup show
4244

4345
# Add nvvm to LD_LIBRARY_PATH.
4446
ENV LD_LIBRARY_PATH="/usr/local/cuda/nvvm/lib64:${LD_LIBRARY_PATH}"
45-
4647
ENV LLVM_LINK_STATIC=1
4748
ENV RUST_LOG=info

container/ubuntu24-cuda12/Dockerfile

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,49 @@
11
FROM nvidia/cuda:12.8.1-cudnn-devel-ubuntu24.04
22

3-
RUN apt-get update
4-
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
3+
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
54
build-essential \
65
clang \
76
curl \
87
libssl-dev \
98
libtinfo-dev \
109
pkg-config \
1110
xz-utils \
12-
zlib1g-dev
11+
zlib1g-dev && \
12+
rm -rf /var/lib/apt/lists/*
1313

1414
# Needed to build `path_tracer`, `optix/ex03_window` example
15-
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
15+
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
1616
cmake \
1717
libfontconfig-dev \
1818
libx11-xcb-dev \
1919
libxcursor-dev \
2020
libxi-dev \
2121
libxinerama-dev \
22-
libxrandr-dev
22+
libxrandr-dev && \
23+
rm -rf /var/lib/apt/lists/*
2324

2425
# Get LLVM 7 & libffi7
2526
WORKDIR /data/llvm7
26-
RUN curl -sSf -L -O http://security.ubuntu.com/ubuntu/pool/universe/libf/libffi7/libffi7_3.3-5ubuntu1_amd64.deb
27-
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7_7.0.1-12_amd64.deb
28-
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-dev_7.0.1-12_amd64.deb
29-
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/libllvm7_7.0.1-12_amd64.deb
30-
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-runtime_7.0.1-12_amd64.deb
31-
RUN apt-get install -y ./*.deb
32-
RUN ln -s /usr/bin/llvm-config-7 /usr/bin/llvm-config
27+
RUN curl -sSf -L -O http://security.ubuntu.com/ubuntu/pool/universe/libf/libffi7/libffi7_3.3-5ubuntu1_amd64.deb && \
28+
curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7_7.0.1-12_amd64.deb && \
29+
curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-dev_7.0.1-12_amd64.deb && \
30+
curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/libllvm7_7.0.1-12_amd64.deb && \
31+
curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-runtime_7.0.1-12_amd64.deb && \
32+
apt-get install -y ./*.deb && \
33+
ln -s /usr/bin/llvm-config-7 /usr/bin/llvm-config && \
34+
rm -rf ./*.deb && \
35+
rm -rf /var/lib/apt/lists/*
3336

3437
# Get Rust
3538
RUN curl -sSf -L https://sh.rustup.rs | bash -s -- -y
3639
ENV PATH="/root/.cargo/bin:${PATH}"
3740

3841
# Setup the workspace
39-
ADD ./rust-toolchain.toml /data/Rust-CUDA/
4042
WORKDIR /data/Rust-CUDA
41-
RUN rustup show
42-
RUN rm -f "rust-toolchain.toml"
43+
RUN --mount=type=bind,source=rust-toolchain.toml,target=/data/Rust-CUDA/rust-toolchain.toml \
44+
rustup show
4345

4446
# Add nvvm to LD_LIBRARY_PATH.
4547
ENV LD_LIBRARY_PATH="/usr/local/cuda/nvvm/lib64:${LD_LIBRARY_PATH}"
46-
4748
ENV LLVM_LINK_STATIC=1
4849
ENV RUST_LOG=info

0 commit comments

Comments
 (0)