Dockerizing LAMP Stack Application

Vrinda Hegde
2 min readOct 3, 2021

In this article we will see how to deploy a LAMP Stack application using docker containers.

Let us create a dockerfile for deploying the application. In this dockerfile we will use ubuntu image as the base image and then install apache and php above it. Then we will create a MYSQL container which will be connected to our application.

Below is the Dockerfile snippet:

In this dockerfile I have installed php 7.3 version which was required for my application.

Use the below command to build the image from the dockerfile:

docker build -f dockerfile-lamp-stack.dockerfile .

Next let us create the containers to deploy the application.

Below is the snippet of docker-compose file:

In the above docker-compose file we are building the LAMP Stack container and MYSQL container.

For the lamp_stack service we need to give the context of the code and place the dockerfile at that loaction in order to build our LAMP Stack image.

We are exposing the port 8010 where the application will be served on the browser.

Next is mysql_service, where we are creating the mysql container by using MYSQL 5.7 version.

In the volumes section we have to use the location to our source code and database dump file respectively on line 25 and 43 respectively.

Use the below commands to create network and volumes respectively:

docker network create lamp-stack-netdocker volume create --name=mysql_storage_01

Now let us create the containers using the below command:

docker-compose -f docker-compose-lamp-stack.yml up -d

Now check if both the containers are up and running using the below command:

docker ps

If both the containers are up and running then check on the browser using: <IP>:8010 or localhost:8010

This will serve the default page on the browser. To connect to the database you will need to use the database details in your php config file.

Hope this article was helpful. Happy Learing!!!

--

--