|
| 1 | +# |
| 2 | +# Dockerfile for a feature-rich code-server with Conda and UV |
| 3 | +# Pre-configured for Asia/Shanghai timezone and Alibaba Cloud PyPI mirror. |
| 4 | +# |
| 5 | + |
| 6 | +# Step 1: Start from the official code-server base image. |
| 7 | +FROM codercom/code-server:latest |
| 8 | + |
| 9 | +# Step 2: Set arguments for tool versions. |
| 10 | +ARG MINIFORGE_VERSION=23.11.0-0 |
| 11 | +ARG PYTHON_VERSION=3.11 |
| 12 | + |
| 13 | +# Step 3: Define environment variables for tool paths and configurations. |
| 14 | +ENV CONDA_DIR=/opt/conda |
| 15 | +ENV UV_DIR=/home/coder/.local |
| 16 | +# Add bin directories to the system PATH. |
| 17 | +ENV PATH=${CONDA_DIR}/bin:${UV_DIR}/bin:${PATH} |
| 18 | +# CRITICAL: Set the timezone environment variable. |
| 19 | +ENV TZ=Asia/Shanghai |
| 20 | +# CRITICAL: Configure UV to use the Alibaba Cloud mirror by default. |
| 21 | +ENV UV_INDEX_URL=https://mirrors.aliyun.com/pypi/simple |
| 22 | + |
| 23 | +# Step 4: Switch to the ROOT user for system-level installations. |
| 24 | +USER root |
| 25 | + |
| 26 | +# Step 5: Install system dependencies, set timezone, and install Miniforge. |
| 27 | +RUN \ |
| 28 | + # Update package lists and install necessary tools |
| 29 | + apt-get update && apt-get install -y --no-install-recommends \ |
| 30 | + wget \ |
| 31 | + curl \ |
| 32 | + git \ |
| 33 | + build-essential \ |
| 34 | + tzdata \ |
| 35 | + # Set the timezone non-interactively |
| 36 | + && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \ |
| 37 | + # Download and install Miniforge |
| 38 | + && wget "https://github.com/conda-forge/miniforge/releases/download/${MINIFORGE_VERSION}/Miniforge3-${MINIFORGE_VERSION}-Linux-x86_64.sh" -O miniforge.sh \ |
| 39 | + && /bin/bash miniforge.sh -b -p ${CONDA_DIR} \ |
| 40 | + && rm miniforge.sh \ |
| 41 | + # Give the 'coder' user ownership of the conda directory |
| 42 | + && chown -R coder:coder ${CONDA_DIR} \ |
| 43 | + # Clean up apt cache to keep the image size down |
| 44 | + && apt-get clean \ |
| 45 | + && rm -rf /var/lib/apt/lists/* |
| 46 | + |
| 47 | +# Step 6: Switch back to the standard, non-root 'coder' user. |
| 48 | +USER coder |
| 49 | + |
| 50 | +# Step 7: As the 'coder' user, install user-specific tools and set up the default environment. |
| 51 | +RUN \ |
| 52 | + # Install 'uv' using its official script |
| 53 | + curl -LsSf https://astral.sh/uv/install.sh | sh && \ |
| 54 | + \ |
| 55 | + # Create a default conda environment |
| 56 | + conda create -n py${PYTHON_VERSION} python=${PYTHON_VERSION} -y && \ |
| 57 | + \ |
| 58 | + # Pre-install common packages into the new environment using 'uv'. |
| 59 | + # This will now automatically use the Alibaba Cloud mirror due to the ENV var. |
| 60 | + uv pip install --python=${CONDA_DIR}/envs/py${PYTHON_VERSION}/bin/python \ |
| 61 | + numpy \ |
| 62 | + pandas \ |
| 63 | + matplotlib \ |
| 64 | + scikit-learn \ |
| 65 | + jupyterlab && \ |
| 66 | + \ |
| 67 | + # Configure the shell to automatically activate this environment on login |
| 68 | + echo "conda activate py${PYTHON_VERSION}" >> ~/.bashrc |
| 69 | + |
| 70 | +# Step 8: The base image's entrypoint will start code-server. |
| 71 | +# All environment variables (TZ, UV_INDEX_URL, PATH) will be inherited. |
0 commit comments