简体   繁体   中英

How to Dockerize a PHP app

I am trying to understand the general process that goes into deploying a PHP web app through Docker. I have a web app developed in LAMP.

So far I understood that firs of all I have to download and install Docker itself. Afterwards I have to install the Docker Composer. Then using the Composer I have to create a container that will contain the image of my server (Apache).

And this is where I get confused. Do I have to then create a container for my database and another one for the application itself (the directory containing the code) or do I have one container for the server the database and the app?

I dont need a detailed explanation, just the general idea behind the process then I can figure out the rest on my own

Thank you to anyone who can provide any help.

There can be many ways but the simple way is to install docker on some linux machine , write a docker file that installs and configures all the necessay components such as apache , php , mysql etc , and then grab your application code either inside the container or attach it as external volume from the host.

After writing dockerfile , you can build the docker image by using the docker build command , and after the image is build you can use it locally or push to dockerhub , or push it to your private docker registery if you want.

The other option is if you just want to test , you can pull an already existing image from dockerhub that contains the LAMP stack and you then just need to do docker run on the image attaching your php application as external volume .

Ofcourse , to access the application on port 80 or 443 outside docker you have to expose those ports either in docker file , or at docker run command time.

For a test environment , you can run all the services in just one container.

For larger Deployements you can consider a container orchestration service such as DockerSwarm or Kubernetes . You can also try DC/OS from MesoSphere , by grabbing a vagrant file from thier github repo that will setup the DC/OS on a single machine for you. Then you can just spin up as many services as you want on Mesos . They provide out of the box support for service installation , container management and scaling.

The best practices recommends to have one Docker container per process/service (one container for Apache + PHP, another container for MySQL and so on) but it's just a guideline and it doesn't mean that you cannot have only one container with everything you need inside it.

If you decide to go with only one container to run all the services, you'll be fine just using Docker (Engine). You can still use Docker Compose in this case but there's no real need for it.

Docker Compose is more helpful when you have to run multiple containers. With just one command you can get all your containers up and running. Also here you can use only Docker Engine but you'll need to run each container manually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM