Hi, my first docker project and learning a lot through the docker step by step manual. But I need some advise on the workflow I should use for my project. I’ve written an app in PHP that uses apache and MySQL. The app talks to an online API every 5min and stores the data it retrieved in the MySQL DB. When my project is finished I would like people to use any online docker (or local) and just download my app and run it.
What I’m thinking of now is making two containers:
Apache + PHP
MySQL + static volume to store the db files on
Questions:
About the Apache + PHP container, when I put my PHP files in the image, what would be the best way to update those files when I update or add new features? Should I also add Git in this image and have the user periodically pull updates?
Or, should I build a new image for every update / feature and have the user pull a new image? Shutdown the running container and deploy a new container with the latest image.
MySQL is running in a different container and I’m using a config.php file that contains the connection IP to the MySQL DB. How can I have the Apache/PHP container find out the IP address of the MySQL DB?
This. Doubly true if the container doesn’t actually have any state on its own and just stores everything in the database; then you can destroy and recreate the container with basically no consequences.
I would write up a Docker Compose file that includes the two containers and a private network. Then the in-docker DNS will provide a host name “mysql” (or whatever you name it in docker-compose.yml) that you can put in a configuration file.
A more flexible, but also more involved, approach to doing this is to write an ENTRYPOINT script that can take the database location from an environment variable and rewrites the configuration file at container startup time. The setup as you describe it almost certainly doesn’t need it, but if you want to deploy the application against an external database, that approach can be helpful.