I'm new to working with Docker and I'm trying to start a project that uses Laravel, PostgreSQL, and React. Is it enough to just create empty containers and then initialize my project in there? I'm also concerned about whether the changes I make will reflect on my host machine and vice versa. If possible, could you provide some example Dockerfiles and a docker-compose file for this stack? I've heard there are ways to make changes sync between the host and the containers, but I'm not sure how to set that up.
2 Answers
I totally recommend using Docker for Laravel! Here's a quick look at my setup:
- I use a custom FrankenPHP image as my web server.
- For my workspaces, I have a separate custom PHP8 image (though sometimes I use the same FrankenPHP image for simplicity).
- My database is backed by PostgreSQL 17, and I also run Portainer for management and pgAdmin for database administration.
- I even use Directus to help with database building.
This setup works great for development!
That sounds cool! What made you choose FrankenPHP?
Understanding how volumes work is crucial here. In my setup, I mount the Laravel source from the host machine. This way, any changes you make in your IDE reflect immediately in the container! Just ensure you have Composer and NodeJS installed in your workspace container to run PHP and npm commands effectively.
So, you really do code in the host environment? That’s neat!
Thanks for explaining that, it's super helpful!
Could you share your docker-compose.yml? I’d love to see how you set it up.