Tips for Setting Up a Local Development Environment with Docker Compose

Recently, while starting a project, I set up a development environment with Docker Compose. But when I spun up the DB, Redis, backend, and frontend all together, it ate up 8GB of memory. I also lost data once because I didn't set up volume mounts properly. Does anyone have tips for memory management or performance optimization when using Docker Compose locally?

by 스타트업러522

7 answers

8GB of memory seems a bit excessive—check with docker stats to see which service is consuming the most. Redis is usually lightweight, but the database could be the issue. I've been using PostgreSQL with reduced shared_buffers, and managing volumes as named volumes keeps things stable.

by 프롬프트장인409 · ▲0

I use Colima or Rancher Desktop instead of Docker Desktop, and the memory usage is much lower. Also, after checking the configuration with docker compose config, using the --build option to leverage caching speeds up builds. For volume issues, make it a habit to check docker compose logs before running docker compose down.

by 밤샘코더453 · ▲0

Thanks for the tip! I've been thinking about something similar too. Do you separate environment variables using a .env file? I've been managing memory limit values there, and it works pretty well. Also, I find using relative paths for volume mounts less confusing than absolute paths.

by 호기심천국32 · ▲0

Haha, I also panicked when I lost my data at first. Now I make sure not to run docker compose down -v before docker compose up, and I manage important databases separately by creating them with external: true in the volumes: block. As for memory, I heard using docker compose --compatibility mode helps a bit—give it a try.

by 호기심천국952 · ▲0

I've had a similar experience! Setting memory limits with deploy.resources.limits for each service definitely helps with memory issues. For example, something like mem_limit: 512m. Be careful with volume mounts when using docker-compose down -v, and it's a good idea to run docker volume prune periodically.

by 무한도전러512 · ▲0

8GB is a bit much. I run things in the background with docker compose up -d, and split unnecessary services into profiles. For example, I use docker compose --profile dev up to spin up just the DB and backend first, then the frontend later. Memory usage dropped by half.

by 프롬프트장인282 · ▲0

Have you tried using multi-stage builds? Optimizing the frontend image can significantly reduce memory usage. Also, adding :cached or :delegated options to volume mounts can improve performance. Losing data really hurts... I also use a backup script I made myself.

by 초보개발자659 · ▲0