This repository demonstrates a basic Django application configured to run inside a Visual Studio Code Development Container. The main goal is to showcase the setup and benefits of a containerized development environment.
- Docker Desktop
- Visual Studio Code
- Dev Containers extension for VS Code
-
Clone the repository and open the folder in Visual Studio Code.
git clone <your-repository-url> cd Dev-Containers-Practice code .
-
Reopen in Container:
- When you open the folder, VS Code will detect the
.devcontainerconfiguration and prompt you to "Reopen in Container". - Click that button.
- If you don't see the prompt, open the Command Palette (
Ctrl+Shift+PorCmd+Shift+P) and runDev Containers: Re-open in Container.
- When you open the folder, VS Code will detect the
-
Wait for the build:
- The first time, Docker will build the image, which may take a few minutes.
- The
postCreateCommandin.devcontainer/devcontainer.jsonwill automatically install all Python dependencies listed inrequirements.txt.
-
Run the Django Server:
- Once the container is running, open a new terminal in VS Code (
Ctrl+orCmd+). - Run the database migrations and start the development server:
python manage.py migrate python manage.py runserver 0.0.0.0:8000
- VS Code should automatically forward port 8000. You can now access the application in your browser at
http://localhost:8000.
- Once the container is running, open a new terminal in VS Code (
.devcontainer/devcontainer.json: This is the core configuration file. It tells VS Code how to build and configure the container, what extensions to install, and what commands to run after creation..devcontainer/setup.sh: A shell script that is run by thepostCreateCommand. It's used here to install Python packages.requirements.txt: Lists the Python dependencies for the project, which are installed automatically when the container is created.