'Alternative or a better method to use pytorch in dockerfilee

My team is building a docker image that uses pytorch. When I am installing pytorch in the conda env, the image size shoots up in GB(s). The current image size is 5GB.

It is not possible to push such huge docker images to deployment as it will take too much time and will be unproductive. What are alternatives to this? Or how to optimize the image size?

This is my current dockerfile:

FROM python:slim
WORKDIR /app
COPY . .
RUN pip3 install -r requirements.txt

RUN apt -qq update \
    && apt -y install wget ffmpeg libsm6 libxext6 \
    && rm -rf /var/lib/apt/lists/*

RUN wget -q https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
    && chmod +x Miniconda3-latest-Linux-x86_64.sh \
    && bash Miniconda3-latest-Linux-x86_64.sh -b -p /opt/miniconda3 \
    && rm Miniconda3-latest-Linux-x86_64.sh \
    && cp /opt/miniconda3/condabin/conda /bin/conda

RUN conda env create -f .condarc.yaml

CMD [ "conda", "run", "-n", "myenv", "CUDA_VISIBLE_DEVICES=0", "python3", "app.py"]

.condarc.yaml:

name: myenv
dependencies:
  - cudatoolkit=10.2
prefix: /opt/miniconda
channel:
  - pytorch

requirements.txt

opencv-python
torch
torchgeometry
torchvision


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source