Skip to content

Commit dc32288

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 dc32288

File tree

4 files changed

+57
-65
lines changed

4 files changed

+57
-65
lines changed

container/rockylinux9-cuda12/Dockerfile

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,38 @@ RUN dnf -y install \
77
redhat-rpm-config \
88
which \
99
xz \
10-
zlib-devel
11-
10+
zlib-devel \
1211
# Needed to build `path_tracer`, `optix/ex03_window` example
13-
RUN dnf -y install \
1412
cmake \
1513
fontconfig-devel \
1614
libX11-devel \
1715
libXcursor-devel \
1816
libXi-devel \
19-
libXrandr-devel
17+
libXrandr-devel && \
18+
dnf clean all
2019

2120
# Get LLVM 7 & libffi.so.6
2221
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
22+
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 && \
23+
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 && \
24+
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 && \
25+
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 && \
26+
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 && \
27+
dnf -y install ./*.rpm && \
28+
ln -s /usr/bin/llvm-config-7-64 /usr/bin/llvm-config && \
29+
rm -rf ./*.rpm && \
30+
dnf clean all
3031

3132
# Get Rust
3233
RUN curl -sSf -L https://sh.rustup.rs | bash -s -- -y
3334
ENV PATH="/root/.cargo/bin:${PATH}"
3435

3536
# Setup the workspace
36-
ADD ./rust-toolchain.toml /data/Rust-CUDA/
37+
COPY ./rust-toolchain.toml /data/Rust-CUDA/
3738
WORKDIR /data/Rust-CUDA
38-
RUN rustup show
39-
RUN rm -f "rust-toolchain.toml"
39+
RUN rustup show && rm -f "rust-toolchain.toml"
4040

4141
# Add nvvm to LD_LIBRARY_PATH.
4242
ENV LD_LIBRARY_PATH="/usr/local/cuda/nvvm/lib64:${LD_LIBRARY_PATH}"
43-
4443
ENV LLVM_LINK_STATIC=1
4544
ENV RUST_LOG=info

container/ubuntu22-cuda11/Dockerfile

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,45 @@
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
13-
11+
zlib1g-dev \
1412
# Needed to build `path_tracer`, `optix/ex03_window` example
15-
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
1613
cmake \
1714
libfontconfig-dev \
1815
libx11-xcb-dev \
1916
libxcursor-dev \
2017
libxi-dev \
2118
libxinerama-dev \
22-
libxrandr-dev
19+
libxrandr-dev && \
20+
rm -rf /var/lib/apt/lists/*
2321

2422
# Get LLVM 7
2523
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
24+
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7_7.0.1-12_amd64.deb && \
25+
curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-dev_7.0.1-12_amd64.deb && \
26+
curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/libllvm7_7.0.1-12_amd64.deb && \
27+
curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-runtime_7.0.1-12_amd64.deb && \
28+
apt-get install -y ./*.deb && \
29+
ln -s /usr/bin/llvm-config-7 /usr/bin/llvm-config && \
30+
rm -rf ./*.deb && \
31+
rm -rf /var/lib/apt/lists/*
3232

3333
# Get Rust
3434
RUN curl -sSf -L https://sh.rustup.rs | bash -s -- -y
3535
ENV PATH="/root/.cargo/bin:${PATH}"
3636

3737
# Setup the workspace
38-
ADD ./rust-toolchain.toml /data/Rust-CUDA/
38+
COPY ./rust-toolchain.toml /data/Rust-CUDA/
3939
WORKDIR /data/Rust-CUDA
40-
RUN rustup show
41-
RUN rm -f "rust-toolchain.toml"
40+
RUN rustup show && rm -f "rust-toolchain.toml"
4241

4342
# Add nvvm to LD_LIBRARY_PATH.
4443
ENV LD_LIBRARY_PATH="/usr/local/cuda/nvvm/lib64:${LD_LIBRARY_PATH}"
45-
4644
ENV LLVM_LINK_STATIC=1
4745
ENV RUST_LOG=info

container/ubuntu22-cuda12/Dockerfile

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,45 @@
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
13-
11+
zlib1g-dev \
1412
# Needed to build `path_tracer`, `optix/ex03_window` example
15-
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
1613
cmake \
1714
libfontconfig-dev \
1815
libx11-xcb-dev \
1916
libxcursor-dev \
2017
libxi-dev \
2118
libxinerama-dev \
22-
libxrandr-dev
19+
libxrandr-dev && \
20+
rm -rf /var/lib/apt/lists/*
2321

2422
# Get LLVM 7
2523
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
24+
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7_7.0.1-12_amd64.deb && \
25+
curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-dev_7.0.1-12_amd64.deb && \
26+
curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/libllvm7_7.0.1-12_amd64.deb && \
27+
curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-runtime_7.0.1-12_amd64.deb && \
28+
apt-get install -y ./*.deb && \
29+
ln -s /usr/bin/llvm-config-7 /usr/bin/llvm-config && \
30+
rm -rf ./*.deb && \
31+
rm -rf /var/lib/apt/lists/*
3232

3333
# Get Rust
3434
RUN curl -sSf -L https://sh.rustup.rs | bash -s -- -y
3535
ENV PATH="/root/.cargo/bin:${PATH}"
3636

3737
# Setup the workspace
38-
ADD ./rust-toolchain.toml /data/Rust-CUDA/
38+
COPY ./rust-toolchain.toml /data/Rust-CUDA/
3939
WORKDIR /data/Rust-CUDA
40-
RUN rustup show
41-
RUN rm -f "rust-toolchain.toml"
40+
RUN rustup show && rm -f "rust-toolchain.toml"
4241

4342
# Add nvvm to LD_LIBRARY_PATH.
4443
ENV LD_LIBRARY_PATH="/usr/local/cuda/nvvm/lib64:${LD_LIBRARY_PATH}"
45-
4644
ENV LLVM_LINK_STATIC=1
4745
ENV RUST_LOG=info

container/ubuntu24-cuda12/Dockerfile

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,45 @@
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
13-
11+
zlib1g-dev \
1412
# Needed to build `path_tracer`, `optix/ex03_window` example
15-
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
1613
cmake \
1714
libfontconfig-dev \
1815
libx11-xcb-dev \
1916
libxcursor-dev \
2017
libxi-dev \
2118
libxinerama-dev \
22-
libxrandr-dev
19+
libxrandr-dev && \
20+
rm -rf /var/lib/apt/lists/*
2321

24-
# Get LLVM 7 & libffi7
2522
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
23+
RUN curl -sSf -L -O http://security.ubuntu.com/ubuntu/pool/universe/libf/libffi7/libffi7_3.3-5ubuntu1_amd64.deb && \
24+
curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7_7.0.1-12_amd64.deb && \
25+
curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-dev_7.0.1-12_amd64.deb && \
26+
curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/libllvm7_7.0.1-12_amd64.deb && \
27+
curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-runtime_7.0.1-12_amd64.deb && \
28+
apt-get install -y ./*.deb && \
29+
ln -s /usr/bin/llvm-config-7 /usr/bin/llvm-config && \
30+
rm -rf ./*.deb && \
31+
rm -rf /var/lib/apt/lists/*
3332

3433
# Get Rust
3534
RUN curl -sSf -L https://sh.rustup.rs | bash -s -- -y
3635
ENV PATH="/root/.cargo/bin:${PATH}"
3736

3837
# Setup the workspace
39-
ADD ./rust-toolchain.toml /data/Rust-CUDA/
38+
COPY ./rust-toolchain.toml ./
4039
WORKDIR /data/Rust-CUDA
41-
RUN rustup show
42-
RUN rm -f "rust-toolchain.toml"
40+
RUN rustup show && rm -f "rust-toolchain.toml"
4341

4442
# Add nvvm to LD_LIBRARY_PATH.
4543
ENV LD_LIBRARY_PATH="/usr/local/cuda/nvvm/lib64:${LD_LIBRARY_PATH}"
46-
4744
ENV LLVM_LINK_STATIC=1
4845
ENV RUST_LOG=info

0 commit comments

Comments
 (0)