Skip to content

Latest commit

 

History

History
82 lines (52 loc) · 1.94 KB

README.md

File metadata and controls

82 lines (52 loc) · 1.94 KB

Python with Docker

The goal of this repo is to run simple Python code within containers.

  • Demo 1: processing example, a simple script.py to run.
  • Demo 2: app server example, running FastAPI with a single endpoint.

Prerequisite: Install Docker

For simplicity I will use Docker and Docker Compose, but it is possible to use Podman and Podman Compose too.

I would recommend using a Linux machine (or Windows Subsystem for Linux) for ease of install and better compatability of tools.

Windows and MacOS do not fully support Docker or Podman natively.

Linux

  • Option 1: Use the install script provided under scripts.
bash 0-docker-install-ubuntu.sh

Windows

  • Option 1: Install Windows Subsystem of Linux, then use an install script under scripts, or follow the official docker install guide: https://docs.docker.com/engine/install/ubuntu/
  • Option 2: Install Windows Subsystem of Linux, and use Docker Desktop.
  • Option 3: Use Docker Desktop with the default Linux (QEMU) virtual machine.

MacOS

Demo 1: Processing

First enter the processing_example directory.

Build the container

docker compose build

Run the container

docker compose up -d

View the logs

docker logs processing_script

A file named processed.csv should be generated in the output directory.

Demo 2: Application

First enter the app_example directory.

Build the container

docker compose build

Run the container

docker compose up -d

Access the API server

Go to localhost:9111 to view the served endpoint.

View the logs

docker logs app_server

You should see a log record of your visit to the root API page.