I've recently made my project open-source and am diving into Docker to make it hostable on various platforms. Previously, I set it up using Pulumi targeting AWS services. Now, as I'm new to Docker and have started additional projects, I'm curious about everyone else's go-to setup for working with Docker in both development and production environments. I tried setting up the development environment, but I had a tough time with volume mounting—my node_modules often get out of sync, which I realize is partially due to my inexperience. I've ended up using docker-compose alongside a dev configuration, but usually, I run my frontend and API directly using a local PostgreSQL instance since it feels quicker. One of the main advantages I see in using Docker is the ability to run containerized tests easily.
4 Answers
When setting up a new project, I typically create a designated folder, craft my Dockerfile, and set up the necessary files. In my docker-compose setup, I mount my local app folder and run it in development mode, which allows for automatic reloading on file changes. I often use SQLite for initial development since it's lightweight, but I implement an ORM to facilitate easy transitions to PostgreSQL in production. During testing, I usually wipe the DB file and restart the container for a fresh instance, all managed through a single compose file.
For development, I keep things pretty straightforward—just run the app directly with a local database, similar to what you're doing. However, Docker shines in production settings. I prefer using a single docker-compose.yml file with profiles for development and production instead of creating separate files; it keeps everything clean and organized. The trick is in configuring your volume mounts correctly to avoid issues with node_modules being overwritten. Also, I highly recommend utilizing multi-stage builds to maintain slim production images.
The node_modules sync issue is a common headache! You can resolve it by using a named volume configuration, like this:
volumes:
- .:/app
- /app/node_modules
This keeps your dependencies within the container separate from the host's bind mount, helping to avoid those sync issues. For separating development and production setups, I use a base compose.yml file with overrides rather than having multiple complete files, which helps with cleanliness.
I prefer to maintain two separate compose files for development and production, and often a third for staging deployments. Each environment has its dedicated database container, and I specify which one to connect to right in the compose configurations. My development happens on my laptop, staging on a server, and production can either be cloud-based or on a server, depending on the project. I usually push updates to staging first, even without testing there manually, and then merge into the main branch. Before starting a major task, I clone the production database to refresh my local development one to ensure everything aligns perfectly. I've also built a local web UI tool to back up all my PostgreSQL containers!

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically