Best way to handle image/container dependency for php site on apache?

I just started using docker a couple of weeks ago and intend to use it to run some PHP sites on apache and ubuntu in Amazon ECS. My question is about the use of FROM in specifying images and layering dependencies.

Originally I’d planned to create an image apache2-php5 (FROM ubuntu) with all of those components and required apache modules enabled, then create an image mysite1 (from apache2-php5) with just my site code and each additional site the same way - mysite2 (from apache2-php5).

After looking at docker-compose; however, and seeing how ECS handles this with multiple containers specified for a single task, I’m now confused b/c (using docker-compose as the example) I can specify other images as requirements for the site image in the docker-compose.yml file and then link the containers.

So now I’m confused about the best way to handle this layering of containers to maximize efficiency, maintenance, portability, and resource utilization.

Based on my current understanding I see 3 options:

  1. Use my originally invisioned method for building the site images, and when I deploy I only need to deploy a container for mysite1 because it will automatically pull down the other images needed.
  2. The image for mysite1 will instead be built FROM the base ubuntu image and when I deploy I will have to state that it requires the apache2-php5 image as well and perhaps link the two containers (?)
  3. I create an image for mysite1 from ubuntu and have all the build for apache, php, etc… performed explicitly in this container in its entirety. This seems less efficient to me if i’m deploying multiple sites with the same underlying apache requirements, but maybe I’m missing something about how that works.

Thanks a ton in advance. I’ve been racking my brains over this one.

Anyone have anything to offer on this?

Linking containers and FROM statements are not related. Your original plan is correct, as far as layering images.

Linking would be if say I have a container running apache named web and then a mysql container named db

I could then do the following:

docker run --name=mysql -e MYSQL_ROOT_PASSWORD=foo -d mysql
docker run --name=web --link=mysql -d nginx

This will add an entry to my web container’s /etc/hosts so that I can reach the mysql container by using the hostname mysql within my web container.

OK - that does make sense. I guess I was just trying to make more of what I’d seen in the docker-compose.yml examples as it related to dependent images. Thanks!