A Streamlit application showcasing the Palmer Penguins dataset, containerized with Docker and deployable to Google Cloud Run.
- Git - Version control
- pyenv and pyenv-virtualenv - Python version management
- Docker - Container runtime
- direnv - Environment variable management (optional but recommended)
- gcloud CLI - Google Cloud SDK (for deployment)
git clone https://github.com/vivadata/docker-101.git
cd docker-101# Install Python 3.11.8 if not already installed
pyenv install 3.11.8
# Create a virtual environment named 'pingouins'
pyenv virtualenv 3.11.8 pingouins
# Set the local Python version for this project
pyenv local pingouinsThe .python-version file will automatically activate the pingouins environment when you enter the directory.
pip install --upgrade pip
pip install -r requirements.txtstreamlit run app.pyThe application will open automatically in your browser at http://localhost:8501. You can stop it in your terminal with CTRL+C.
# Rename the template file
cp .env.copy .env
# Create .envrc file for direnv
echo 'dotenv' > .envrc
# Allow direnv to load the environment variables
direnv allowEdit the .env file and replace the placeholder values:
# .env
LOCATION=europe-west1 # Your GCP region
PROJECT_ID=your-project-id # Your GCP project ID
REPOSITORY=your-artifact-registry # Your Artifact Registry name
IMAGE=little-pengouins # Your image name
PORT=8080 # Application portUsing the Makefile:
# Build the Docker image
make build
# Build and run the container
make runOr using Docker commands directly:
# Build
docker build -t little-pengouins .
# Run
docker run -p 8080:8080 -e PORT=8080 little-pengouinsAccess the application at http://localhost:8080.
Ensure you have:
- A Google Cloud Platform account
- The
gcloudCLI installed and configured - A GCP project created
# Login to GCP
gcloud auth login
# Set your project
gcloud config set project YOUR_PROJECT_ID# Set variables (or source from .env)
export LOCATION="europe-west1"
export PROJECT_ID="your-project-id"
export REPOSITORY="asod-public-images"
# Create the repository
gcloud artifacts repositories create ${REPOSITORY} \
--repository-format=docker \
--location=${LOCATION} \
--description="Docker repository for Streamlit apps"
# Configure Docker authentication
gcloud auth configure-docker ${LOCATION}-docker.pkg.devChoose the appropriate build command based on your machine:
For Linux/Cloud Shell:
make build_gcpFor Mac (M1/M2/M3):
make build_gcp_macThis builds the image with the correct platform for Cloud Run.
make push_gcpOr manually:
docker push ${LOCATION}-docker.pkg.dev/${PROJECT_ID}/${REPOSITORY}/${IMAGE}gcloud run deploy little-pengouins \
--image=${LOCATION}-docker.pkg.dev/${PROJECT_ID}/${REPOSITORY}/${IMAGE} \
--platform=managed \
--region=${LOCATION} \
--allow-unauthenticated \
--port=8080After deployment, Cloud Run will provide a URL where your application is accessible.
docker-101/
βββ app.py # Streamlit application
βββ requirements.txt # Python dependencies
βββ Dockerfile # Container definition
βββ Makefile # Build and deploy commands
βββ .env.copy # Environment variables template
βββ .envrc # direnv configuration
βββ .python-version # pyenv virtual environment
βββ .gitignore # Git ignore rules
βββ README.md # This file
| Command | Description |
|---|---|
make hello |
Test command |
make build |
Build Docker image locally |
make run |
Build and run container locally |
make build_gcp |
Build image for GCP (Linux/Cloud Shell) |
make build_gcp_mac |
Build image for GCP (Mac M1/M2/M3) |
make push_gcp |
Build and push image to Artifact Registry |
# Find and kill the process using port 8080
lsof -ti:8080 | xargs kill -9# Add your user to the docker group (Linux)
sudo usermod -aG docker $USER# Ensure direnv is hooked to your shell
# Add to ~/.zshrc or ~/.bashrc:
eval "$(direnv hook zsh)" # for zshThis project is for educational purposes.
Happy Coding! π§