Install Laravel In Docker

I’m a Developer who last 6 years using C#, Asp.Net, SQL Server and Oracle.
And now I’m trying to learn Laravel Php Framework.
Training for Laravel need of using MySQL. I decide to use Docker image of MySQL.

  1. Docker Compose installed, following Step 1 of How To Install Docker Compose on Ubuntu 18.04. Step 1 — Downloading Laravel and Installing Dependencies. As a first step, we will get the latest version of Laravel and install the dependencies for the project, including Composer, the application-level package manager for PHP. We will install these.
  2. Before we deploy our fresh Laravel app to our docker we need to update and add some fields on our Laravel.env. If you don’t wanna use your Laravel.env variables then you may manually update the docker-compose.yml file however in this tutorial I will be using the laravel.env variables. DBCONNECTION=pgsql; DBDATABASE=yourdesireddb.
  3. An up-to-date guide/tutorial on how to create a reusable Laravel 6/7/8+ Docker development environment (PHP 7/8+, Nginx or Apache, MySQL, Mailhog, PhpMyAdmin).
Install laravel through docker

Docker installed on your server, following Steps 1 and 2 of How To Install and Use Docker on Ubuntu 20.04. Docker Compose installed on your server, following Step 1 of How To Install and Use Docker Compose on Ubuntu 20.04. Step 1 — Obtaining the Demo Application. To get started, we’ll fetch the demo Laravel application from its Github. Laradock Vs Laravel Homestead. Laradock is the Docker counterpart of Laravel Homestead. While both tools could provide a robust development environment, Laradock offers the following benefits: Lightweight and scalable. Unlike homestead, Laradock splits up all of software into isolatable docker containers.

1. step, download and install Docker Community Edition for Windows

2. step, test Docker does work correctly
c:> docker run hello-world
If Docker running properly go to the next step.

3. step, download and run mysql container
c:> docker run –name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=pasw123456 -d mysql/mysql-server:latest

4. step, try to access to mysql container, learn IP address of the container
List running Docker containers, you will see Container ID, Image, Names, … info
c:> docker ps -a
Running mysql Docker container ID is 9535aa43b64d
Inspect all information about mysql container using this Container ID
c:> docker inspect 9535aa43b64d
You will see “IPAddress”: “172.xx.xx.xx” in my case this is
The basic test to access container is using Ping command
c:> ping
Reply from Destination host unreachable.
Ping statistics for Packets: Sent = 4, Received = 0, Lost = 4 (100% loss)
Why I can’t access the container?
Because my Windows 10 Host system IP address is Docker mysql container address is
They are on different IP subnets and can’t communicate with each other.
To solve this problem I need to define a new route for my Windows host system.
This route definition will help Windows host to reach to the Docker mysql container.

5. step, add route definition on Windows 10 to access mysql Docker container
Open Command Prompt as Administrator and run route command
c:> route /P add MASK
Test again communication between the host and mysql container
c:> ping
Reply from bytes=32 time<1ms TTL=63
Finally, we can communicate with the mysql Docker container.

6. step, connect o mysql with Database Workbench tool
I try to connect but got a message, “Can’t connect to MySQL server on ”
The reason for this message is mysql not configured for remote connection.
I can connect only from localhost to mysql.


7. step, connect to running mysql container and configure mysql for remote connection
Connect to mysql Docker container :
c:> docker exec -it 9535aa43b64d bash
Connect to mysql server :
mysql -u root -p
List user and host access information :
SELECT host, user FROM mysql.user;
Create a mysql user ‘root’ that can connect to mysql from anywhere.
CREATE USER ‘root’@’%’ IDENTIFIED BY ‘pasw123456’;
I now again trying to connect and again I get a different error message.
Error message: ‘Authentication plugin ‘caching_sha2_password’ cannot be loaded’

Install Laravel In Docker


Laravel Install Docker Is Not Running

Install laravel through docker

8. step, change mysql password type to ‘mysql_native_password’
ALTER USER ‘root’@’%’ IDENTIFIED WITH mysql_native_password BY ‘pasw123456’;

Finally, I can connect to mysql container and can create a database, tables and views.