DEV Community

Chris Chen
Chris Chen

Posted on

My go-to docker-compose setup for Python development

I've been using docker-compose instead of venv module for Python development for a while. Here is my go-to setup, please feel free to give me some suggestions and comments!


Folder Structure

Folder Structure

Dockefile

# base image
FROM python:3.10

# install packages
RUN apt-get update \
    && apt-get upgrade -y
RUN apt-get install -y \
    vim \
    curl \
    pandoc \
    texlive-xetex \
    texlive-fonts-recommended \
    texlive-plain-generic

# create user and home directory
RUN useradd -m -d /home/devuser -s /bin/bash devuser
USER devuser

ENV PATH=/home/devuser/.local/bin:$PATH

# upgrade pip and install python packages
RUN /usr/local/bin/python -m pip install --upgrade pip
COPY requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

docker-compose.yml

version: '3.8'
services:
  jupyterlab:
    container_name: jupyterlab
    build: .
    ports:
      # for jupyter lab
      - 8888:8888
    volumes:
      - ./src:/home/devuser/src
    working_dir: /home/devuser/src
    command: jupyter lab --port=8888 --ip=0.0.0.0
Enter fullscreen mode Exit fullscreen mode

And then just docker-compose up -d --build, you'll have your docker container up and running!
To get the url or token for jupyter lab, simply run docker logs jupyterlab

This is how I like to setup my Python environment for data processing-related project.

Top comments (0)