Basic Lamp stack with Docker using Docker compose

Published on: 2019.05.07

Author: Erik Maier

An image

This is a small guide to help beginners setting up their local development environment using Docker on Linux.

Step 0 (optional)

If you are new to Docker watch at least, the two videos below:

Getting started with Docker

Docker with docker compose

Step 1 - Install Docker and Docker Compose

 curl -fsSL get.docker.com -o get-docker.sh
 sudo sh get-docker.sh
 sudo usermod -aG docker your-user                #run docker as non-root user

For more info visit: Docker Docs

Step 2 - Add your app files

Your directory structure should look like this:

data       # your database mount
docker     # your docker related conf and script files
docker-compose.yml    # this docker compose file
public                # your apps public files
app                   # app files
etc

Step 3 Build your docker compose file

version: '3'
services:
  web:
    container_name: server_1
    image: rkmaier/apache2-php7:1.0.0
    ports:
      - 80:80
    restart: always
    tty: true
    stdin_open: true
    links:
      - db
    volumes:
      - ./:/var/www
      - ./data/logs/apache:/var/log/apache2

  db:
    container_name: database_1
    image: mariadb:10.0
    ports:  
      - 3306:3306
    volumes:
      - ./data:/var/lib/mysql # Mysql database mount location        
      - ./docker/conf/my.cnf:/etc/mysql/my.cnf  # Mysql config file

    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USER: erik
      MYSQL_PASSWORD: skipjack
      MYSQL_DATABASE: database_1

  adminer:
    container_name: adminer
    image: adminer
    restart: always
    volumes:
      - ./docker/conf/adminer.ini:/usr/local/etc/php/conf.d/0-upload_large_dumps.ini # Adminer conf file
    ports:
      - 8080:8080
    links:
      - db

Dockerhub info

Source files

Step 4 - Start your Docker containers

docker-compose up 

Step 5 - Import your database

Use adminer at http://localhost:8080 and import your database

Step 6 - Update your hosts file

Map http://local.myapp.com domain to localhost in your local hosts files

Note:

For more complex projects with a lot of different services you might want to use something like Laradock or Vessel for you Docker setup.