Install Laravel On Docker

Download and install Laravel from repository:

Clone Laravel and create project from repository:

I'm having a problem installing laravel through a dockerfile. I'm using docker-compose that pulls a dockerfile where I basically have this: FROM php:7.3-apache-stretch.some apt-get and install composer. WORKDIR /var/www RUN composer create-project -prefer-dist laravel/laravel app CMD apachectl -D FOREGROUND. Install Docker for your OS, clone this repo, add your Laravel app files to the src directory, and from the root project directory you just cloned run: docker-compose build && docker-compose up -d.

Get into the folder and run composer

  • In this case, our Laravel application will be created in the /var/www/laraveldocker directory of the php-apache container. However, it will be persisted in the src directory in the project directory on the local development machine.
  • 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).
See full list on

Set permissions on the project directory so that it is owned by your non-root user:

Create and set up docker-compose.yml

Since we feel lucky today, we’ll create our docker-compose file with some customization over the containers names and ports redirects, in order not to use too common names and ports, that might conflict with some other containers on our host.

You can take a look at the final version of the docker-compose.yml file some lines below.

We’ll create 3 containers:

  • app named as app101 which holds our laravel app. Feeds from the Dockerfile we’ll create later.
  • webserver named as webserver2 which holds our web-server; nginx for this example. This service exposes port 8101 for default 80, and 8102 for 443, ad it feeds from the image nginx:alpine
  • db named as db2 which holds the MySQL service. This service exposes port 8103 for default 3306. We also must set the database name (laravel_docker) and the mysql password for root user (password admin for this example).

Persisting Data

We’ll add some extra configuration to our docker-compose file; we need to add volumes to our db service. Without them, every time the container stops or fails, all data would be missing.

So here we are telling that everything inside /var/lib/mysql will be replicated into the dbdata folder of our host. Plus, we persist the configuration of the database on /etc/mysql/my.cnf.


We also set the volume to be mounted on the local driver:

Our final docker-compose.yml file looks like:

Create Dockerfile

Now for making docker-compose to run, we need to create a Dockerfile file to set the image we named as laravel-sandbox, and set php, folders and ports as well.

Setting PHP

Create file laravel-sandbox/php/local.ini

Install laravel on docker windows

Setting Nginx

Create file laravel-sandox/nginx/conf.d/app.conf

Setting MySQL

Install Laravel On Docker Windows

Create file laravel-sandbox/mysql/my.cnf

Running the container

Firt copy and rename the .env envioroment file for our app:

And set the correct values for the database connection due the values set on our docker-compose.yml

And finally we can run the container

Now, if everything went as expected and if type from the console

We should see something as:

We can run now the 2 extra following commands from the console for adding some security to our app.

So we added our encrypted key for the container and cached our configuration.

Migrating data

Now we have everything up && running, we should be able to see our app from the browser (http://localhost)

For migrating data, we first must create an user for the database. So we first we access to the database this way:

And then we can access to the mysql client

The console will prompt asking for the password (MYSQL_ROOT_PASSWORD param on docker-compose.yml)

Now we should be able to see the database by typing:

mysql> show databases;

And create the user by typing the following commands:

Now we can skip out from the container;

Now we can permform the migrations;


At this point, we might be interested on adding a user to the databases and performing actions for loged-in users. So from the console we perform make:auth:

Then we can add some /database/seeds/UsersTableSeeder.php to our project and enable it on DatabaseSeeder.php


Install Laravel In Docker Container


Install Laravel On Ubuntu Docker

Now we execute composer dump-autoload in order to make noticeof the new generated file:

And fillally we proceed to execute the seeder

See Full List On

Now we can login into our app with user specified on UsersTableSeeder.php!