Development Environment Using Docker for Laravel Applications

development environment docker lemp laravel

This article provides details on how to setup development environment using Docker implementing a LEMP server used for hosting Laravel applications.

  • L - Linux
  • E - Nginx
  • M - MySQL
  • P - PHP

In particular, the flavours and versions of the LEMP components used in this stack are as follows:

[LEMP] = Ubuntu 18.04 Base Image + Nginx + MySQL + PHP 7.2

This docker container along with basic Laravel 8 install is available from this repository.

Below is a guide to get this up and running.

Quick Start Guide

To get this development environment up and running simply build the docker container and start it using the following commands from within the docker directory.

> cd docker

> ./

> ./

You can access the application at

Once finished call the stop command to bring down docker container and application.

> ./

The following section provides further details on the docker methods used.

Using Quick Start Guide

Below shows the quick start commands being executed.

Dev Env Docker

The results of visiting local running from docker development environment.

Browser Laravel

Folder Structure

├── docker
│   ├──
│   ├── docker-compose.yml
│   ├── lemp-base
│   │   └── Dockerfile
│   ├── lemp-dev
│   │   ├── Dockerfile
│   │   ├── conf
│   │   └── setup
│   ├──
│   └──
└── www
    ├── index.html
    └── laravelwebapp
        ├── app
        ├── artisan
        ├── bootstrap
        ├── composer.json
        ├── composer.lock
        ├── config
        ├── database
        ├── package.json
        ├── phpunit.xml
        ├── public
        ├── resources
        ├── routes
        ├── server.php
        ├── storage
        ├── tests
        ├── vendor
        └── webpack.mix.js


You only need to build the application once. Once built, you can simply run the application each time you need to use this development environment to develop your Laravel application.

Follow the two steps to build your docker development environment

1. Build the base image.

> cd docker/lemp-base

> docker build . -t lemp-dev-base

Check image with name ‘lemp-dev-base’ has been created

> docker images

2. Build the application image (which will utilise the base image created in step 1).

Move into directory ‘docker/lemp-dev’.

> cd ..

> cd lemp-dev

Build the application image

> docker build . -t lemp-dev

Again, to check this image was created run the command and look for ‘lemp-dev’ has been created

> docker images


Navigate to directory ‘/docker’ and start the docker container using

> docker-compose up -d

This will start a docker container named ‘laravelwebapp’. serving up the contents of folder ‘/www/’.

To connect directly to this container (LEMP server)

> docker exec -it laravelwebapp /bin/bash

To stop the docker container use

> docker-compose down


View web page at the following url


Served from folder ‘/www/index.html’



Served from Laravel application ‘/www/laravelwebapp/public’

MySQL Database

A database is setup as part of this development environment and has been preconfigured for a basic Laravel application.

You can see the SQL script used to setup the database in the directory.



# Creating the MySQL database

# Creating the MySQL user 
CREATE USER 'laravel_user'@'%' 
IDENTIFIED WITH mysql_native_password BY 'password';

TO 'laravel_user'@'%';

USE `laravel`;

If you want to connect to this database, then you can connect directly to this container (LEMP server)

> docker exec -it laravelwebapp /bin/bash

Once into the server, you can simply start up the command line client using the command below.

> mysql

You will be logged in as root. This is considered safe in a development environment, but using root in production should be avoided.

To show databases

mysql> show databases;

mysql> show databases;
| Database           |
| information_schema |
| laravel            |
| mysql              |
| performance_schema |
| sys                |
5 rows in set (0.00 sec)
DevEnv Docker MySql

You can see the Laravel data that has been created. The credentials for this database are already populated in the .env file.


If you want to test the DB connection in your Laravel application, you can check this using tinker.

> php artisan tinker

tinker> DB::connection()->getPdo();

php artisan migrate:status

MySQL from local machine

You can also connect to the MySQL database inside of the docker container from your local machine.

To do this, simply use the credentials below

Use the credentials in the command below to access mysql in your docker container.

  • Host:
  • User: laravel_user
  • Password: password

> mysql -h -u laravel_user -p

The details for this used and password are actually stored in an sql file which is used to configure the database config file in the previous section where you can set up databases, users and tables etc.

Creating your first programming language is easier than you think,
...also looks great on your resume/cv.