Skip to content

Playing around with docker images, python and streamlit

Notifications You must be signed in to change notification settings

eitancj/python_in_docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Using Docker to Containerize a Python App


Just experimenting with building Docker images.
Containerizing a Python3-Streamlit app, in this case.

Inspired by this short guide which I recommend.

Pre-installed on your machine

  • Git
  • Docker

A simple way to work with Docker images locally:
https://www.docker.com/products/docker-desktop/

Tech Stack

  • Tested on macOS X
  • Python 3.11.4
  • Streamlit
  • Debian-based container

Running the App

  1. Clone git repo & cd into it
git clone https://github.com/eitancj/python_in_docker
cd python_in_docker
  1. Build image
docker build -t python_in_docker:V1 .

# May take a few minutes: Streamlit is relatively heavy
  1. Verify image creation
docker images python_in_docker
  1. Run app
docker run -d --rm -p 8501:8501 --name pydock python_in_docker:V1

# Make sure no other running process is using that port on your machine
  1. Test app
open http://localhost:8501 # will open in your default web browser

# Or simply copy and paste the address into your web browser
  1. Gracefully stop (and remove) container when you're done
docker container stop pydock
  1. Remove the created image
docker rmi python_in_docker:V1
  1. Clean up local copy (unless you want to keep it)
cd .. && rm -rf python_in_docker

# BE PRUDENT WITH 'rm -rf'.
# Make sure you're in the right directory and aiming at the right folder.
  1. That's it