This is a minimal starter project for Python development using Docker containers and VSCode Dev Containers.
- Install Docker Desktop and VSCode.
- Install the Dev Containers extension in VSCode (Microsoft).
- Clone this repository:
gh repo clone sheepnir/my-python-container-project
- Rename the local project folder:
mv my-python-container-project my-new-project cd my-new-project - Remove old Git history and initialize a fresh repo:
rm -rf .git git init git add . git commit -m "Initial commit"
- Create a new GitHub repository and push:
gh repo create my-new-project --public --source=. --remote=origin git push -u origin main
- Open the project in VSCode.
- When prompted, click "Reopen in Container".
- Open the folder in VSCode.
- It will automatically build and start the container.
- Your code (inside
/app) will be live inside the container. - Modify any Python file — no need to rebuild unless you change Python packages.
- Add the package name to
requirements.txt. - Rebuild the container:
- Open Command Palette (
Cmd + Shift + P) → Dev Containers: Rebuild Container. - Or click the green corner button in VSCode and select Rebuild Container.
- Open Command Palette (
- Open a terminal in VSCode (inside the container).
- Run:
python main.py
- The Flask app will start and listen on
0.0.0.0:5000.
Even though the app runs inside a container, it will be automatically forwarded to your Mac.
Open your browser and navigate to:
http://localhost:5000
You should see:
Hello from inside the container!
When you are done working on this project and want to switch:
- Simply close the VSCode window.
- This automatically stops and removes the running container.
- Open your next project folder and Reopen in Container if needed.
Alternatively, you can manually stop containers using Docker Desktop.
| Task | Command |
|---|---|
| Rebuild container after changing requirements | Dev Containers: Rebuild Container |
| Open a shell inside the container | Open Terminal in VSCode |
| Stop container | Close VSCode window or use Docker Desktop |
Your Mac remains clean, and each project stays fully isolated inside its container.
Happy Coding!