Build OCI container images from Python projects directly in Visual Studio Code — no Docker required.
- 🚀 Build Containers - Build OCI images with a single command
- 🔄 Push to Registry - Push images to GHCR, ACR, Docker Hub
- ⚙️ Configuration - Generate
pycontainer.tomlconfiguration - 📊 Output Channel - View build progress in real-time
- 🐍 Python Native - No Docker daemon needed
- Visual Studio Code 1.80.0 or higher
- Python 3.11 or higher
- pycontainer-build (automatically installed if needed)
- Open VS Code
- Press
Ctrl+Shift+X(Windows/Linux) orCmd+Shift+X(Mac) - Search for "pycontainer-build"
- Click Install
code --install-extension vscode-pycontainer-0.1.0.vsix- Open a Python project with
pyproject.toml - Open Command Palette (
Ctrl+Shift+PorCmd+Shift+P) - Type "pycontainer: Build Container Image"
- Enter image tag (e.g.,
myapp:latest) - View build progress in the output panel
- Open Command Palette
- Type "pycontainer: Build and Push Container Image"
- Enter image tag (e.g.,
ghcr.io/user/myapp:v1) - Image will be built and pushed to registry
- Open Command Palette
- Type "pycontainer: Configure Container Build"
- A
pycontainer.tomlfile will be created - Edit the configuration as needed
Right-click on pyproject.toml in the Explorer:
- Select "Build Container Image"
Configure the extension in VS Code settings:
{
"pycontainer.pythonPath": "python",
"pycontainer.defaultTag": "myapp:latest",
"pycontainer.defaultBaseImage": "python:3.11-slim",
"pycontainer.autoInstall": true,
"pycontainer.showOutput": true,
"pycontainer.verbose": false
}Create pycontainer.toml in your project:
[build]
base_image = "python:3.11-slim"
workdir = "/app"
include_deps = true
[build.env]
ENV = "production"
PORT = "8080"
[registry]
url = "ghcr.io/user/myapp"| Command | Description | Keyboard Shortcut |
|---|---|---|
pycontainer.build |
Build container image | - |
pycontainer.buildAndPush |
Build and push image | - |
pycontainer.configure |
Create configuration file | - |
# main.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}# pyproject.toml
[project]
name = "myapi"
version = "1.0.0"
dependencies = ["fastapi", "uvicorn"]
[project.scripts]
start = "uvicorn main:app --host 0.0.0.0 --port 8000"Build: Open Command Palette → "Build Container Image" → Enter myapi:latest
# app.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"# pycontainer.toml
[build]
base_image = "python:3.11-slim"
include_deps = true
[build.env]
FLASK_APP = "app"
FLASK_ENV = "production"Build: Right-click pyproject.toml → "Build Container Image"
Use the extension locally, then deploy with GitHub Actions:
# .github/workflows/build.yml
name: Build Container
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Build and push
run: |
pip install pycontainer-build
pycontainer build --tag ghcr.io/${{ github.repository }}:latest --push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}The extension will automatically prompt to install it. Or install manually:
pip install pycontainer-buildEnsure your workspace has a pyproject.toml file at the root.
For registry push, ensure you're authenticated:
# GitHub Container Registry
echo $GITHUB_TOKEN | docker login ghcr.io -u USERNAME --password-stdin
# Azure Container Registry
az acr login --name myregistryConfigure the correct Python path in settings:
{
"pycontainer.pythonPath": "/usr/bin/python3.11"
}cd plugins/vscode-pycontainer
npm install
npm run compilenpm run packageThis creates vscode-pycontainer-0.1.0.vsix.
- Press F5 in VS Code to open Extension Development Host
- Test commands in the new window
- Interactive configuration wizard
- Build status in status bar
- Quick pick for recent images
- Integration with Docker extension
- Multi-platform build support
- Build history view
Contributions welcome! See CONTRIBUTING.md.
MIT License - See LICENSE file for details.
- pycontainer-build - Core builder
- poetry-pycontainer - Poetry plugin
- hatch-pycontainer - Hatch plugin