Devcontainer: Optimize apt-get commands to reduce Docker image size (#152882)

## Summary
- Added --no-install-recommends flag to all apt-get install commands to reduce unnecessary dependencies
- Added apt-get clean after package installations to remove package cache and reduce image size
- Combined multiple apt commands into single instructions to reduce Docker image layers

## Test plan
Test by building the devcontainer and verifying functionality while ensuring reduced image size
Pull Request resolved: https://github.com/pytorch/pytorch/pull/152882
Approved by: https://github.com/cyyever, https://github.com/atalman, https://github.com/Skylion007
This commit is contained in:
Wouter Devriendt
2025-05-06 20:33:02 +00:00
committed by PyTorch MergeBot
parent ed63cb20ec
commit 5fe58ab5bd

View File

@ -14,11 +14,8 @@ RUN apt-get -y update && \
libopenblas-dev libopenblas-dev
# Tools needed for llvm # Tools needed for llvm
RUN apt-get install -y \ RUN apt-get install --no-install-recommends -y lsb-release wget software-properties-common gnupg && \
lsb-release \ sudo apt-get clean -y
wget \
software-properties-common \
gnupg
# Create Python virtual environment # Create Python virtual environment
# RUN python3 -m venv /opt/venv # RUN python3 -m venv /opt/venv
@ -33,7 +30,8 @@ RUN if [ -n "$CLANG_VERSION" ]; then \
./llvm.sh "${CLANG_VERSION}"; \ ./llvm.sh "${CLANG_VERSION}"; \
echo 'export CC=clang' >> ~/.bashrc; \ echo 'export CC=clang' >> ~/.bashrc; \
echo 'export CXX=clang++' >> ~/.bashrc; \ echo 'export CXX=clang++' >> ~/.bashrc; \
apt install -y clang libomp-dev; \ apt-get install --no-install-recommends -y clang libomp-dev && \
apt-get clean -y; \
fi fi
@ -43,7 +41,8 @@ RUN if [ -n "$CUDA_VERSION" ]; then \
CUDA_REPO_VERSION=$(echo ${CUDA_VERSION} | sed 's/\./\-/g'); \ CUDA_REPO_VERSION=$(echo ${CUDA_VERSION} | sed 's/\./\-/g'); \
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.0-1_all.deb && \ wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.0-1_all.deb && \
dpkg -i cuda-keyring_1.0-1_all.deb && \ dpkg -i cuda-keyring_1.0-1_all.deb && \
apt-get install -y cuda-toolkit-${CUDA_VERSION}; \ apt-get install --no-install-recommends -y cuda-toolkit-${CUDA_VERSION} && \
apt-get clean -y; \
fi fi
# Set PATH for CUDA # Set PATH for CUDA