Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Summary

This directory contains a Docker-based development environment template with:

A guide to set up Docker-based projects using the template, customize it for your needs, and maintain it over time.

Description of Files

Workflows

How to Customize a Project Template

Description of Executables

copy_docker_files.py

docker_bash.sh

docker_build.sh

docker_clean.sh

docker_cmd.sh

docker_exec.sh

docker_jupyter.sh

docker_push.sh

run_jupyter.sh

utils.sh

version.sh

Template Customization and Maintenance

Quick Start for New Projects

Step 1: Copy the Template

> cd class_project/project_template
> cp -r . /path/to/your/new/project
> cd /path/to/your/new/project

Step 2: Choose a Base Image

The template includes three Dockerfile options. Choose the one that best fits your project:

OptionFileBest For
StandardDockerfile.ubuntuFull Ubuntu environment with system tools
LightweightDockerfile.python_slimMinimal Python environment; reduced image size
Modern Package ManagerDockerfile.uvFast dependency resolution with uv

How to choose:

Step 3: Set Up Your Dockerfile

Step 4: Keep Customization Minimal

Understanding the Dockerfile Flow

Each Dockerfile follows the same structure. Here are the key stages:

Stage 1: Base Image and System Setup

FROM ubuntu:24.04  # or python:3.12-slim, depending on your requirement
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get -y update && apt-get -y upgrade

Stage 2: System Utilities (Ubuntu-based Dockerfiles Only)

RUN apt install -y --no-install-recommends \
    sudo \
    curl \
    systemctl \
    gnupg \
    git \
    vim

Stage 3: Python and Build Tools (Ubuntu-based Dockerfiles Only)

RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    python3 \
    python3-pip \
    python3-dev \
    python3-venv \
    && rm -rf /var/lib/apt/lists/*

Stage 4: Virtual Environment Setup

RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
RUN python -m pip install --upgrade pip

Stage 5: Jupyter Installation

RUN pip install jupyterlab jupyterlab_vim

Stage 6: Project Dependencies

COPY requirements.txt /install/requirements.txt
RUN pip install --no-cache-dir -r /install/requirements.txt

Stage 7: Configuration

COPY etc_sudoers /etc/sudoers
COPY bashrc /root/.bashrc

Stage 8: Version Logging

ADD version.sh /install/
RUN /install/version.sh 2>&1 | tee version.log

Stage 9: Port Declaration

EXPOSE 8888

Best Practices: Keep It Simple

The Core Principle

Only change what’s necessary for your project. Everything else should inherit from the template.

This approach:

How to Do It Right

WhatWhereExample
Project Python packagesrequirements.txtnumpy==1.24.0
Jupyter + Vim (always there)Dockerfile Stage 5jupyterlab jupyterlab_vim
System toolsDockerfile apt-get sectionpostgresql-client
Shell aliasesbashrcalias jlab="jupyter lab"
Custom scriptsscripts/ directorySetup or initialization scripts
User permissionsetc_sudoersGrant passwordless sudo

Wrong Vs. Right Approach

.Dockerignore Policy

Why It Matters

The .dockerignore file prevents unnecessary files from being added to the Docker build context:

What to Exclude: Category Breakdown

Workflow: From Template to Your Project

Complete Setup Checklist

Maintaining Your Setup

Document Any Changes

Monitor Package Versions

Keep .dockerignore Updated

Contribute Improvements Back

When you improve your project’s Docker setup:

Example improvements:

Troubleshooting

Build Is Slow

Image Is Too Large

Package Not Found Error

Permission Issues in Container

Jupyter Won’t Connect

Vim Keybindings Not Working