Jump to content

Docker Basic Question


Drongo_III

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.