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


# 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 \

# 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


version: '3.8'
    container_name: jupyterlab
    build: .
      # for jupyter lab
      - 8888:8888
      - ./src:/home/devuser/src
    working_dir: /home/devuser/src
    command: jupyter lab --port=8888 --ip=
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)

12 APIs That You Will Love

Free and easy to use APIs for your next project, learning a new technology, or building a new feature.