Dear Community,
I’m pretty new do Docker. I played a lot with Docker in my development environment but I tried to deploy real app only once.
I’ve read tons of documentations and watched dozes of videos but still have a lot of questions.
I do understand that Docker is just a tool that can be used in so many different ways, but now I’m trying to find the best way to develop and deploy web apps.
I’ll use real PHP App case to make my question more concrete and practical.
To keep it simple let’s assume I’m building a very simple PHP App so I’ll need:
- Web Server (nginx)
- PHP Interpreter (php-fpm or hhvm)
- Persistent storage for SESSIONs
The best example/tutorial I could find was this one year old post. Dylan proposes this kind of structure:
He use Data Only container for the whole PHP project files and logs and docker-compose
to run all this images with proper links. In development env I’ll mount a host directory as a data volume and for production I’ll copy files directly to Data Only Images and deploy.
This is understandable. I do want to share data across nginx
and php-fpm
. nginx
needs access to static files (.img, .css, .js…) and php-fpm
need access to PHP files. And both services are separated so can be updated/changed independently.
Data only container shares a data volume
that is linked to nginx
and php-fpm
by --volumes-from
option.
But as I understand - there’s a problem with Data Only containers and -v
flag.
Official Docker Documentation says that data volume
is specially-designated directory to persist data! It is said that ‘Data volumes persist even if the container itself is deleted.’. So this solution is great for data I do not want to loose like Session files, DB storage, logs etc… But not for my code files, right? I do want to change my code files. I want to deploy changes without rebuilding nginx
and php-fpm
images.
Another problem is when I tried this approach I could not deploy code changes until I stopped all running containers, removed them and their images and rebuild them entirely. Just rebuilding and deploying Data Only images did nothing!
I’ve seen some other implementations when data is stored directly in Interpreter container, but it’s not an option because I need nginx
to have access to these files also.
The question is what is the best practices on where to put my project code files and how to deploying changes for this kind of app?
Thanks.