|
| 1 | +# Use an official Ubuntu as a parent image |
| 2 | +FROM ubuntu:20.04 |
| 3 | + |
| 4 | +# Set environment variables to prevent interactive prompts during installation |
| 5 | +ENV DEBIAN_FRONTEND=noninteractive |
| 6 | + |
| 7 | +# Install system dependencies |
| 8 | +RUN apt-get update && apt-get install -y \ |
| 9 | + wget \ |
| 10 | + git \ |
| 11 | + bzip2 \ |
| 12 | + ca-certificates \ |
| 13 | + libglib2.0-0 \ |
| 14 | + libxext6 \ |
| 15 | + libsm6 \ |
| 16 | + libxrender1 \ |
| 17 | + && rm -rf /var/lib/apt/lists/* |
| 18 | + |
| 19 | +# Install Miniconda |
| 20 | +ENV CONDA_DIR=/opt/conda |
| 21 | +RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && \ |
| 22 | + bash /tmp/miniconda.sh -b -p $CONDA_DIR && \ |
| 23 | + rm /tmp/miniconda.sh && \ |
| 24 | + $CONDA_DIR/bin/conda clean --all --yes |
| 25 | + |
| 26 | +# Update PATH environment variable |
| 27 | +ENV PATH=$CONDA_DIR/bin:$PATH |
| 28 | + |
| 29 | +# Create the Conda environment |
| 30 | +RUN conda create --name layer_skip python=3.10 -y |
| 31 | + |
| 32 | +# Activate the Conda environment and install PyTorch and dependencies via Conda |
| 33 | +RUN echo "source activate layer_skip" >> ~/.bashrc |
| 34 | +ENV CONDA_DEFAULT_ENV=layer_skip |
| 35 | +ENV PATH=$CONDA_DIR/envs/layer_skip/bin:$PATH |
| 36 | + |
| 37 | +# Install PyTorch CPU-only and other dependencies using Conda |
| 38 | +RUN conda install pytorch==2.2.1 torchvision==0.17.1 torchaudio==2.2.1 cpuonly -c pytorch -y |
| 39 | + |
| 40 | +# Copy and install Python dependencies via pip (excluding torch, torchvision, torchaudio) |
| 41 | +COPY requirements.txt /app/requirements.txt |
| 42 | +RUN pip install --upgrade pip && \ |
| 43 | + pip install --no-cache-dir -r /app/requirements.txt |
| 44 | + |
| 45 | +# Copy the entire project into the Docker image |
| 46 | +COPY . /app |
| 47 | + |
| 48 | +# Set the working directory |
| 49 | +WORKDIR /app |
| 50 | + |
| 51 | +# Copy the entrypoint script |
| 52 | +COPY entrypoint.sh /entrypoint.sh |
| 53 | +RUN chmod +x /entrypoint.sh |
| 54 | + |
| 55 | +# Expose any necessary ports (if applicable) |
| 56 | +# EXPOSE 8000 |
| 57 | + |
| 58 | +# Set the entrypoint |
| 59 | +ENTRYPOINT ["/entrypoint.sh"] |
0 commit comments