Drongo_III Posted February 27, 2018 Share Posted February 27, 2018 Hi Guys I have a basic question around Docker, which I'm right at the start of learning. I'm building a basic LAMP environment and I've come across a few pointers in the docks which seem to indicate (though don't explicitly state) that you should create containers so they run a single service per container. What this appears to mean is that for a LAMP environment I should have Apache+PHP on one container and MySQL on another container. So my questions... 1) Is this in fact the best practice way of building containers and environments? If yes, 2) How do they work together and talk to each other to form an environment? 3) Should you have multiple dockerfiles for each container housing a service (e.g. apche+php) 4) Should your application code go on the apache+php container? Or should that be a container in itself? Sorry if these are really noob questions but I'm more used to paradigm of VMs so docker is a bit confusing. Thanks, Drongo Quote Link to comment https://forums.phpfreaks.com/topic/306691-docker-basic-question/ Share on other sites More sharing options...
gizmola Posted February 28, 2018 Share Posted February 28, 2018 1) Is this in fact the best practice way of building containers and environments? Yes. The property of a container is that it is lightweight. So you want it to be self contained and good at doing the one thing you need it to do. 2) How do they work together and talk to each other to form an environment? The same way that you would have them talk and work together if they were on a network-- via docker networking and docker DNS. You can also create a docker compose file, which can be used with docker swarm in a production environment to orchestrate a group of containers that are designed to work together. 3) Should you have multiple dockerfiles for each container housing a service (e.g. apche+php) No. You can create any number of containers from an image. Images are built from dockerfiles. A single image can support a variety of options as well. You see this when you specify a tag when starting a container. 4) Should your application code go on the apache+php container? Or should that be a container in itself? It should be in a Docker volume, just as you use docker volumes for things like the filesystem you are going to attach to your running mysql server. Quote Link to comment https://forums.phpfreaks.com/topic/306691-docker-basic-question/#findComment-1556790 Share on other sites More sharing options...
Drongo_III Posted March 1, 2018 Author Share Posted March 1, 2018 (edited) 1) Is this in fact the best practice way of building containers and environments? Yes. The property of a container is that it is lightweight. So you want it to be self contained and good at doing the one thing you need it to do. 2) How do they work together and talk to each other to form an environment? The same way that you would have them talk and work together if they were on a network-- via docker networking and docker DNS. You can also create a docker compose file, which can be used with docker swarm in a production environment to orchestrate a group of containers that are designed to work together. 3) Should you have multiple dockerfiles for each container housing a service (e.g. apche+php) No. You can create any number of containers from an image. Images are built from dockerfiles. A single image can support a variety of options as well. You see this when you specify a tag when starting a container. 4) Should your application code go on the apache+php container? Or should that be a container in itself? It should be in a Docker volume, just as you use docker volumes for things like the filesystem you are going to attach to your running mysql server. Hi Gizmola Thank you for your detailed response. I really appreciate the help as wrapping my head around this is taking precious time. I'm still a little confused on the 'single responsibility' approach to creating services. For instance, looking on Dockerhub there are images for Centos, httpd, PHP. And presumably it's preferable to use the official Dockerhub images than spinning up centos and installing apache/php myself? Assuming using the Dockerhub images is the correct method then should I have three dockerfiles as follows? one dockerfile with: FROM centos:7 one dockerfile with: FROM httpd:latest one dockerfile with: FROM PHP:7 Then I just network these (guessing bridge network) and the services automatically know how to talk to each other? Sorry if I'm labouring this one, just want to get the concepts right before diving in. Thanks, Drongo Edited March 1, 2018 by Drongo_III Quote Link to comment https://forums.phpfreaks.com/topic/306691-docker-basic-question/#findComment-1556838 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.