Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

martinszeltins's avatar

I don't understand Docker - what am I missing?

So I started learning about Docker. And as far as I understand you bundle everything into one image for your app. But it doesn't make sense to me.

  1. If you bundle everything for every app into an image then that is a huge overhead. If you need 10 PHP applications then you would end up with 10 PHP installations (one for each docker image)? Makes no sense to me...

  2. If containers don't persist data, then how can you use a database?

0 likes
5 replies
ftiersch's avatar

That's the actual point of docker. Optimally you wouldn't end up with 10 PHP applications but you would create 10 application containers that you link up to a PHP container.

Your second question first: Containers don't persist data but you can mount volumes into them from your host. So your host persists the data and that data is passed into the container so changes in the database aren't lost once the container is removed.

Now the first question:

There are multiple advantages:

  1. You can switch out components easily. Instead of updating a software (lets say redis) you simply boot up a container with a different version.
  2. You can simulate environments more easily. If your docker container runs great on your local environment chances are very high it will run the same way on the server.

But all of that depends on how it is used.

martinszeltins's avatar

@ftiersch thanks for the explanation, just a few more questions I'm wondering about...

you would create 10 application containers that you link up to a PHP container

I didn't know about linking up containers, I will have to look that up.

So your host persists the data and that data is passed into the container

How does that work? How would I get my app (which is running inside the container) to get my host to save data to the database?

ftiersch's avatar

Linking is basically THE best part about docker :) Otherwise you could just use virtual machines like Homestead but the whole point is usually to reduce overhead by reusing containers and keeping them as small as possible (but like I said - that doesn't ALWAYS work).

That's what mounting a volume does. You basically tell Docker when you start up a container with a mounted volume "alright docker... any changes that happen to this directory will have to be synced both ways... so if someone creates (or changes or deletes) a file inside the container -> sync it to the host... if someone does it on the host -> sync it to the container"... so basically you don't have to do anything except tell Docker to create that volume at the beginning.

martinszeltins's avatar

Thanks for pointing me in the right direction @ftiersch I will keep learning about these things. At first it is kind of difficult to wrap my head around it. But containers seem to be getting very popular.

Please or to participate in this conversation.