This project provides a complete development environment using VS Code Dev Containers with Python, Node.js, and MariaDB.
Before getting started, ensure you have the following installed on your machine:
- Docker Desktop (Windows/Mac) or Docker Engine (Linux)
- Download from https://www.docker.com/products/docker-desktop
- Visual Studio Code
- Download from https://code.visualstudio.com/
- Dev Containers extension for VS Code
- Install from VS Code Extensions marketplace or here
git clone <your-repository-url>
cd <your-project-directory>Or create a new project directory:
mkdir my-project
cd my-projectEnsure your project has the following structure:
your-project/
├── .devcontainer/
│ ├── devcontainer.json
│ ├── docker-compose.yml
│ └── Dockerfile
├── ... (your project files)
- Open VS Code
- Open your project folder (
File > Open Folder...) - When prompted, click "Reopen in Container" or:
- Press
F1orCtrl+Shift+P(Windows/Linux) /Cmd+Shift+P(Mac) - Type and select "Dev Containers: Reopen in Container"
- Press
VS Code will build the Docker containers and set up your development environment. This may take a few minutes on the first run.
The development environment includes:
-
Application Container
- Python 3.11
- Node.js 20.x (latest LTS)
- npm (latest version)
- Common development tools
-
MariaDB Database
- Version: 10.11
- Port: 3306
- Database name:
devdb - Username:
devuser - Password:
devpassword - Root password:
rootpassword
- 3306: MariaDB database
- 3000: Node.js application (when running)
The container includes Python 3.11 with common linting and formatting tools:
# Run Python scripts
python your_script.py
# Install Python packages
pip install package-name
# Or use requirements.txt
pip install -r requirements.txtAvailable Python tools:
- autopep8
- black
- yapf
- bandit
- flake8
- mypy
- pycodestyle
- pydocstyle
- pylint
# Check Node.js version
node --version
# Initialize a new Node.js project
npm init
# Install dependencies
npm install package-name
# Run Node.js applications
node app.js
# Or use npm scripts
npm startConnect to MariaDB from your applications using:
- Host:
db(from within containers) orlocalhost(from host machine) - Port:
3306 - Database:
devdb - Username:
devuser - Password:
devpassword
Example Python connection:
import mysql.connector
connection = mysql.connector.connect(
host="db",
port=3306,
database="devdb",
user="devuser",
password="devpassword"
)Example Node.js connection:
const mysql = require('mysql2');
const connection = mysql.createConnection({
host: 'db',
port: 3306,
database: 'devdb',
user: 'devuser',
password: 'devpassword'
});Access the database directly:
# Connect to MariaDB as devuser
mysql -h db -u devuser -pdevpassword devdb
# Connect as root
mysql -h db -u root -prootpasswordThe following extensions are automatically installed in the container:
- ESLint
- Prettier
- Python
- Pylance
- Ensure Docker is running
- Check Docker logs:
docker-compose -f .devcontainer/docker-compose.yml logs - Try rebuilding: In VS Code, run "Dev Containers: Rebuild Container"
- Wait for the database to fully initialize (check logs)
- Verify credentials match those in docker-compose.yml
- Ensure you're using
dbas the hostname when connecting from the app container
If ports 3306 or 3000 are already in use on your host:
- Stop any local MySQL/MariaDB or Node.js services
- Or modify the port mappings in docker-compose.yml
The container runs as the vscode user. If you encounter permission issues:
# Switch to root temporarily
sudo command-here
# Or change file ownership
sudo chown vscode:vscode file-or-directoryCreate a requirements.txt file in your project root:
flask==2.3.0
django==4.2.0
requests==2.31.0Then install in the container:
pip install -r requirements.txtCreate a package.json file or install directly:
npm install express mongoose dotenvTo add system packages or tools, modify .devcontainer/Dockerfile:
# Add this after the existing RUN command
RUN apt-get update && apt-get install -y \
your-package-here \
&& rm -rf /var/lib/apt/lists/*Then rebuild the container in VS Code.
- MariaDB data is persisted in a Docker volume named
mariadb-data - Node modules are stored in a separate volume for better performance
- Your code is mounted from your local machine and changes are reflected immediately
To remove the containers and volumes:
# Stop and remove containers
docker-compose -f .devcontainer/docker-compose.yml down
# Remove volumes (this will delete database data!)
docker-compose -f .devcontainer/docker-compose.yml down -v- VS Code Dev Containers Documentation
- Python Documentation
- Node.js Documentation
- MariaDB Documentation
If you encounter issues not covered in this README:
- Check the VS Code Dev Containers troubleshooting guide
- Review Docker logs for specific error messages
- Ensure all prerequisites are properly installed and up to date