Skip to the content.

LAMP with Docker

1. Create Project Directory

mkdir lamp-docker
cd lamp-docker/

2. Create docker-compose.yml File

Create the docker-compose.yml file with the following content:

version: '3.8'

services:
  web:
    image: php:7.4-apache
    container_name: my_lamp_web
    ports:
      - '8080:80'
    volumes:
      - ./html:/var/www/html
    networks:
      - lamp_network

  db:
    image: mysql:5.7
    container_name: my_lamp_db
    environment:
      MYSQL_ROOT_PASSWORD: root # MySQL root user password
      MYSQL_DATABASE: mydb # Database name to be created (if desired)
      MYSQL_USER: user # Username to be created (if desired)
      MYSQL_PASSWORD: user # Password for the user (if desired)
    volumes:
      - ./mysql:/var/lib/mysql
    networks:
      - lamp_network

  adminer:
    image: adminer
    container_name: my_adminer
    ports:
      - '8081:8080'
    networks:
      - lamp_network

networks:
  lamp_network:
    driver: bridge

3. Create HTML Directory and PHP File

mkdir html
vi html/index.php

Add the following content to index.php:

<?php
phpinfo();
?>

4. Start Docker Containers

docker-compose up -d

5. Check Running Containers

docker ps

6. Access the Application

7. Stop Docker Containers

docker-compose down
wget https://osmankayi.com/docker/lamp.with.docker.sh
chmod +x lamp.with.docker.sh
bash lamp.with.docker.sh

Ref: LAMP Stack Built with Docker Compose