5

I need an image with all the 3 elements combined in one container. But however I Google'd or searched over Docker Hub there I found no images to hold PHP, Apache and MySQL in the same container / Dockerfile.

Can anybody suggest the way to create the desired container?

I would also appreciate the explanation for the rationale of why this kind of images/containers is not available?

As a side note I myself cannot imagine a point making a separation of the MySQL server in the different container feasible due to the fact that the DB itself is not saved with the container and there is only MySQL server in it. So even MySQL being in the same container still perfectly decoupled from the DB itself.

2
  • 1
    Look for a Docker LAMP image. Commented Oct 22, 2019 at 6:56
  • @ Nigel Ren, this is the quickest and most effective solution. Thanks a lot. I just searched lamp over Docker Hub and got quite many up-to-date often-loaded images with Dockerfile's to learn from. Commented Oct 22, 2019 at 7:31

3 Answers 3

6

Good Morning bob-12345

The Point of docker containers is to get a more flexible architecture.

I will make a Example from my work life:

You have an application thats run on php7.0 you now want to test if it still works with php 7.3 so you just stops the php 7.0 container and starts the 7.3 one and checks your application. Or you want to check if it still works with ngnx and php-fpm and so on...

So it is not recommended to put your webserver your coding layer and your persisent layer in one container due versioning issues.

If you still want to have it all in one. I would suggest you start with a plain debian/ubuntu/whatEverDistroYouPrefer and start building like you would do it on a regular webserver.

For Example:

FROM debian:latest
RUN apt-get update \ 
&& apt-get install -y --no-install-recommends \ 
&& http \
&& php \ 
...

I hope Icould Help you :)

Sign up to request clarification or add additional context in comments.

2 Comments

@ bomel2k9, thanks for the explanations. From my perspective the goal is to so encapsulate the service that the DB server is not exposed at all in the kind of the separate container.
Out db data is at a kind of "shared" Storage where the containers (which are duplicated on heavy load times) are connected to. But it is all managed in the aws cloud so i'm not totally sure how it is handled excactly
2

PHP and Apache together in the same container is a good idea - in a practical sense, PHP is only really useful when combined with a webserver (generally speaking). The same cannot be said for MySQL. There are real world problems around scalability, redundancy and availability that cannot be solved if the database server and volume is bundled up with the application code.

Lets say you've deployed your "LAMP Image" into production and your website becomes really popular - cool! You're receiving a lot of traffic and you need multiple instances of your application running. You also need a read-replica of your database.

How are you going to do that if everything is bundled into a single image? You're forced to run the same number of MySQL instances as the number of applications.

3 Comments

@ Luke Joshua Park, thanks for the explanations. "How are you going to do that if everything is bundled into a single image?" My point is that I do not bundle the persisted production DB in the image. I plan to keep it separate so that MySQL servers from the image instances all share the same persisted DB (not sure though how it is done technically).
@bob-12345 That's not really how it works unfortunately - you can't have an arbitrary number of MySQL instances sharing the same data directory of the same file system. A more viable approach here is to cluster/shard/replicate/whatever your MySQL instances and keep them separate from the PHP/Apache application. What you suggest is fine for local development but is a fairly poor idea in production.
@Luke_Joshua_Park, I see, thanks. This "cluster/shard/replicate/whatever your MySQL instances" is the area to research and learn deeper for me.
1

The later me to answer the question of the earlier me.

The need to have PHP and MySQL in the same container comes from a wish to make the portable package of these.

As later me sees it, the solution is not in combining both in the same container but instead under the same Docker Compose docker-compose.yml that easily connects 3 containers (Apache, PHP, MySQL).

Docker Compose is Docker containers orchestrator. It can start, stop, remove, recreate a package of containers. So it makes the package portable.

The quick Google search for docker-compose php apache mysql reveals a number of useful examples of docker-compose.yml. This is just one of them.

This is so much easier and fun with Docker / Compose as soon as you get used to it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.