Thursday, January 10, 2019

How to Setup LAMP Stack on Docker System


Docker: 
Docker is the most revolutionized technology in virtualization world nowadays. Docker is actually an open source project which provides container technology. A container is a lightweight VM(virtual machine) or a process which allows us to install Linux based applications inside it. The container doesn’t have its own Kernel, RAM, CPU and Disk but it uses the underlying OS kernel, RAM, CPU cores and Disk.

In my this blog, I'm going to demonstrate, How to setup LAMP Stack on Docker system.


We will Create 3 Container as follow:
  • Apache + PHP Container
  • MySQL Container
  • PhpMyAdmin Container
Prerequisites: 
  • Docker
  • Docker-compose
Step 1- Install Docker:
Before we provision our LAMP Stack, we need docker installed on your host. Follow my previous blog for installing Docker.
https://linuxhowtoguide.blogspot.com/2018/08/how-to-install-docker-in-ubuntu-1604-lts.html

Step 2- Install Docker-compose:
$ curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Make docker-compose executable
$ chmod +x /usr/local/bin/docker-compose
Step 3- Clone git repository on your local system and change directory
Run the following command to clone git repository
$ git clone https://github.com/amarsingh3d/Docker-LAMP.git
Change Directory
$ cd Docker-LAMP
Step 4- Create Folder to mount with Apache and MySQL container
Before, we provision our LAMP container environment. First, We need to complete some prerequisites. 1-We will setup Two Directories, One for DocumentRoot and Second for MySQL database directory. Run the following command to setup two directories.
$ sh setupdir.sh
Copy phpinfo.php to DocumentRoot
$ copy phpinfo.php DocumentRoot
Once Directory setup successfully, we can proceed to provision LAMP Container stack
Step 5-  Setup Container for LAMP Stack
To provision LAMP stack run following command.
$ docker-compuse up -d
Validate Created Container:
$ docker container ls
You will see three up and running container. 
CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS                            NAMES
326da5972785        phpmyadmin/phpmyadmin          "/run.sh supervisord…"   About an hour ago   Up About an hour    9000/tcp, 0.0.0.0:8080->80/tcp   docker-lamp_phpmyadmin_1
c1a700d81c42        amarsingh3d/apache2.4-php7.2   "/bin/sh -c '/usr/sb…"   About an hour ago   Up About an hour    0.0.0.0:80->80/tcp               docker-lamp_www_1
7480657c8ced        mysql:5.6                      "docker-entrypoint.s…"   About an hour ago   Up About an hour    0.0.0.0:3306->3306/tcp           docker-lamp_db_1
All Three Containers are up and running.
Step 6- Verify Container and Services:
In order to verify Apache container, check your Docker host IP address and access IP Address in the browser. In my case, My IP address is following

Verify PhpMyAdmin Access
To access PhpMyAdmin go to browser and access Docker host IP with port 8080
http://10.0.1.170:8080/
We have successfully setup LAMP stack on Docker host.

2 comments:

  1. Thanks man!!!! its helped me...

    ReplyDelete
  2. Great work.
    Can you describe how to use apache and php in a separate containers and how they will communicate?

    ReplyDelete