Set Up of a Django Project with PostgreSQL, Celery, Valkey, and RabbitMQ Using VSCode Dev Containers and Docker Compose

Set Up of a Django Project with PostgreSQL, Celery, Valkey, and RabbitMQ Using VSCode Dev Containers and Docker Compose

·

2 min read

Why Use VSCode Dev Containers?

Consider the time wasted installing and maintaining virtual environments or system dependencies across different setups. VSCode Dev Containers eliminate this hassle by containerizing everything. You'll have a clean machine without dependency conflicts, where every team member enjoys a consistent development setup.

For a full documentation on setting up dev containers please check this official link, I use this as a reference for this project.

You can find my repository and detailed setup instructions here.

Requirements

  • Linux: Docker, VSCode, VSCode Dev Containers extension

  • Mac OS: Docker Desktop, VSCode, VSCode Dev Containers extension (use Apple Silicon version for better performance on M1/M2)

  • Windows: Docker Desktop, VSCode, VSCode Dev Containers extension

Dev container setup configurations and components

This VSCode dev container setup for a Django, PostgreSQL, Celery, Valkey, and RabbitMQ project includes the following configurations and components:

  1. Configuration Files:

    • devcontainer.json is the primary configuration file.

    • Initialize Command: Copies .devcontainer/.env.dev to .env for environment setup.

  2. Docker and Docker Compose:

    • Uses ../docker-compose.yml to define and run the multi-container application.

    • At /.docker/uvicorn/Dockerfile, it sets the default command to run the Django development server using Uvicorn and generates SSL Certificates for development environment

  3. VSCode Customizations:

    • Extensions:

      • Django-related extensions for HTML, IntelliSense, and general support.

      • Python extensions for linting and code analysis.

      • Docker extension for container management.

      • GitLab extension for workflow integration.

    • Settings:

      • Sets the Python interpreter path to /usr/local/bin/python.
  4. Development Features:

    • Git, Python, Bash commands, Devcontainers CLI, Homebrew package management, Prettier, Pylint, Zsh plugins, and Jira CLI are included.
  5. Port Forwarding:

    • Forwards necessary ports for development:

      • 8000: Django

      • 5432: PostgreSQL

      • 6379: Valkey

      • 5672: RabbitMQ (AMQP)

      • 15672: RabbitMQ Management UI

This setup ensures a consistent development environment with all necessary tools, extensions, and configurations pre-installed and ready to use.


Thank you for reading until the end! If you have any questions or feedback, feel free to leave a comment. If you found it helpful too, give back and show your support by clicking heart or like, share this article as a conversation starter and join my newsletter so that we can continue learning together and you won’t miss any future posts.

💡
👋 Kindness is contagious. Please leave your appreciation by commenting on this post! It takes one minute and is worth it for your career.

Did you find this article valuable?

Support anj in tech by becoming a sponsor. Any amount is appreciated!