I’m a beginner in Django and new to Docker and looking to transition my Django development workflow to use Docker instead of virtualenv. Until now, I’ve been using a setup where:
My development machine is a Raspberry Pi running a virtual environment (venv) with Django and MySQL installed.
I connect to the Raspberry Pi from my Windows laptop via SSH using VS Code for coding and debugging.
Now, I want to run multiple Django apps, each in its own Docker container, with PostgreSQL in a separate container. My questions are:
Is it possible to continue working as I currently do, connecting from my laptop via SSH to the Raspberry Pi and then directly accessing the Docker container with the Django app using VS Code?
Is switching to Docker for Django development a better approach compared to using virtualenv? I assumed Docker would offer more flexibility and isolation, but I’d love to hear from others about their experiences and advice.
<opinion>
I (almost) never use docker for development environments. Yes, I understand there can be a lot of benefits, but for Django, we’ve never encountered a situation where doing so has been considered the desired solution.
I run a lot of projects that all use a common set of in-house created packages. It’s important to me that a family of projects all be using the same versions of those libraries, and so those projects all share the same venv. I don’t see where using Docker would facilitate that. </opinion>
We have a project where we do this - but the development is done natively. It gets deployed through the creation of containers.
The suite of programs running for the project are controlled by a docker compose file. So for runtime, we find Docker to be an ideal solution. (Oh, and it’s a single shared PostgreSQL instance for all of them - each system has its own database. We do not run PostgreSQL in containers.)
thx for explanation.
Maybe you’re wright that this is not a good/ideal solution. I wil stay with venv for now if it goes to dev and maybe ready projects into containers but its a long way to go.
What I do suggest is that you be very clear on what the objective is for doing this, and that you understand why you think that doing it this way is beneficial.
Fwiw… I used Docker for local development for ages, with containers for Django and Postgres. Eventually I decided this was over the top (for me) and made things too complicated.
So I now run Django locally (using uv to manage python versions, environments, etc) but I still use Docker for each site’s Postgres database, and Redis, if needed.
I could use SQLite, but I prefer to use the same database as the production server. I could install Postgres in my MacBook and use that directly, but I’ve had issues before when upgrading things via homebrew, and breaking Postgres. So, for me, using Docker only for the databases is, for me, currently, the best balance.
Funny enough it is what i thought to do after explanation of @KenWhitesell.
His opinion made me think if i really need everth in containers. I’ve tested it and venv seems much simpler then containers. I just dockerized posgresql database and wil keep my django app in venv. After time i should see if it works for me. I am beginner in Django so for me is important to learn django and indeed venv is much easier so with your opinion that this will be just overkil for my skills level. Thx a lot for all your reactions.
Tomas, I rarely answer questions in places like stack overflow or this django forum in order not to sound like someone who talks too much. You ever notice that once you say something, well, if you haven’t thought it out you can sound like a fool. I think philgyford said it all when he says, “SQLite”. That’s a keyword you can’t look past because it can do just as much as postgres, only he doesn’t use it because he favors the production leg in testing and in production. Docker is used for deployment, otherwise venv locally.
I’m not sure if the last sentence is about what I posted, but to clarify: I don’t use Docker for “deployment” at all. I only use Docker in local development, for Postgres and Redis containers.
Thank you for sharing your perspective @CosmoRied. I can see where you’re coming from about contributing to forums—it’s always tricky to strike the right balance in discussions.
To be honest, this is also why I tend to avoid posting questions on forums. Sometimes the discussions can veer off-topic, and I don’t want to contribute to irrelevant or potentially annoying threads. However, I really appreciate the helpful insights shared here, especially in the initial reactions.
I think what @philgyford mentioned about Dockerizing Django only for deployment will be also my choice. My original question was more about whether I should switch to Docker for my development workflow instead of continuing with venv. I was looking to learn from the experiences of more seasoned developers, and I’m grateful for the insights shared so far.
As for the database choice, I already had a clear idea of sticking with PostgreSQL due to its features and professional usage in many setups. SQLite is undoubtedly a great option, but I think it’s important to develop in an environment that closely mirrors production setup. That’s why I’ve chosen PostgreSQL as my database for both development and deployment, and i think that dockerizing it can bring benefits.
For now, I’ll proceed with using venv for Django development and a Dockerized PostgreSQL database. I’ll evaluate this approach over time and come to my own conclusions as I grow more comfortable with Django.
Thank you again to everyone who contributed their thoughts—it’s been very helpful!
Sorry, you’re wright. you were clear about indeed and i got your idea so what i meant to say is that i stay with venv and would use databases in containers. Once again thx for all reactions.