Laravel + Docker Laradock usage environment construction

Introducing the development environment for running Laravel using Laradock. Since I am learning by myself through trial and error, there may be some mistakes, but I would appreciate it if you could point out in that case.

Get ready to use Docker

-Install Docker-for-mac ・ Start Docker

Development environment construction by Laradock

We will build a development environment to run Laravel using Laradock.

What is Laradock

The official website has a wonderful environment for running Laravel (PHP) projects on Docker.

By using Laradock, you can easily build a web server or database on Docker.


-You can easily switch PHP versions (7.3 / 7.2 / 7.1 / 5.6) -You can choose your favorite database engine (MySQL / Postgres / MariaDB ...) ・ Combination of original software such as Memcached, HHVM, Beanstalkd is possible -All software such as PHP-FPM, NGINX, PHP-CLI work in separate containers · All Docker images are built from officially based images You can use Laradock for each project or a single Laradock for all projects.

Open a terminal and create a directory

First, open a terminal and match the path to the location where you want to create the directory. You can find the location of your current file path with pwd.

//It will display the location of the current directory with an absolute path.
$ pwd
//Create a new directory.
$mkdir directory name
//Change to the directory created by the cd command.
$cd Created directory name
//Check the absolute path of the created directory
$ pwd

Install laradock

After creating the directory, install laradock there.

Execute the following command.

//I am doing that I copy the laradock file from GitHub using a mechanism called git
$ git clone -b v9.6

You should see a few lines of message saying Cloning into'laradock' ...

When you are done, check if the directory called ls command is created.

$ ls


Create a laradock .env file

Next, create an .env file, which is one of the files related to the laradock settings. laradock prepares an env-example file as a template for the .env file, so I will create it based on this.

Please enter the following:

$ cd laradock
$ cp env-example .env

cp is a command to copy files.

cp Copy source file name Enter the copy destination file name to use.

You have now created an .env file based on your env-example file.

Edit the laradock .env file

Next, use an editor etc. to edit the .env file.

└── Created directory
    └── laradock
        └── .env

After opening the .env file, find each of the following parts and change them as described.

//Change before
//After change
//A directory to sync on the Laradock web server. Laradock itself does not have to be on docker separately, so only the directory of the laravel project is synchronized. The directory name where laravel will be mounted.
//A directory on your local PC that stores docker storage, etc. By default, databases etc. are saved in your home directory. Change it under the project directory
//If you want to create a new laradock environment for each project, change the directory name to the one you created.
COMPOSE_PROJECT_NAME=Created directory name

Launch the development environment using Docker

Next, use Docker to start the development environment.

The unit of each service running on Docker is called a container.

Here, start the following four containers.

・ Workspace ・ Php-fpm ・ Nginx ・ Postgres

php-What is fpm
PHP FastCGI(The process started at the time of the first request is retained in the memory, and the process retained in the memory is executed for the next request.

It has the following functions.

Loose(graceful)Stop/Advanced process management including launch functionality

Different uid/gid/chroot/Starting a worker in environment, listening on different ports, different php.Use of ini(safe_Alternative to mode)

Log output to standard output and standard error output

Emergency reboot if opcode cache is corrupted

Fast upload support

"slowlog" -Recording scripts with very long execution times(It records the PHP backtrace as well as the script name. To get a backtrace, execute the remote process using ptrace or an equivalent mechanism_Read data)

fastcgi_finish_request() -Something time-consuming process(Video conversion, statistical information processing, etc.)A special function to terminate the request and output all the data while continuing

dynamic/Invoking a static child process

Basic SAPI operating status(Apache mod_Equivalent to status)

php.ini-based config file
What is CGI
PHP on the web server(Languages that generate dynamic content)It is a mechanism to operate.
CGI spawns and destroys processes whenever a user requests them. If there is a large number of requests, processes will be created and destroyed accordingly, which will lead to poor performance.
What is FastCGI
The process started at the time of the first request is retained in the memory, and the process retained in the memory is executed for the next request. It solves CGI problems, speeds up programs and reduces server load.

There is postgres in the container to start, which is a database system called PostgreSQL.

This time, PostgreSQL will use version 11.6.

Therefore, modify the first line of the Dockerfile in the laradock / postgres directory as follows.


1  FROM postgres:11.6

After editing, go to "Created Directory / laradock Directory" in the terminal.

$ cd ~/Created directory/laradock

Then enter the following command.

$ docker-compose up -d workspace php-fpm nginx postgres

The meaning of the command is as follows.

docker-compose is a command to use a function called Docker Compose that handles multiple containers at the same time. up is the command used to start the container with Docker Compose -d is an option to return to terminal operation after starting the container

When I run the command, I get a lot of messages.

At the first time, the software itself (Docker image) of each container is downloaded, so it takes about several minutes to start the container.

Finally, if you see the following message, the container has started successfully.

Creating Created directory_docker-in-docker_1 ... done
Creating Created directory_workspace_1        ... done
Creating Created directory_php-fpm_1          ... done
Creating Created directory_nginx_1            ... done
Creating Created directory_porstgres_1        ... done

If you don't see these 5 messages, try docker-compose up -d workspace php-fpm nginx postgres again.

Once the container has started, launch your browser and type localhost in the address bar.

If you get 404 Not Found, it's OK.

If you want to stop the container, enter the following command.

$ docker-compose stop

If you want to restart the container, enter the following command.

docker-compose up -d workspace php-fpm nginx postgres

Install Laravel

Enter the following command in the created directory / laradock directory.

$ docker-compose exec workspace composer create-project --prefer-dist laravel/laravel . "6.8.*"

To execute the command starting with docker-compose, you need to move to the created directory / laradock directory and then execute it.

The installation will take a few minutes. When the message is displayed, many files should be created under the created directory / laravel directory.

If you wait for a while, the installation will not start,

  Could not find package laravel/laravel with version 6.8.*.

If the message is displayed, change the "6.8. *" Part of the command to "6. *. *" And install.

Visit Laravel's welcome page

After installing Laravel, access localhost with your browser. It is OK if the following screen is displayed.

スクリーンショット 2020-10-31 0.51.38.png

Set Laravel time to Japan time

By default, Laravel's time setting is UTC (Coordinated Universal Time), which is 9 hours later than Japan time.

Change this to Japan time.

Please change the timezone of / created directory / laravel / config / app.php to'Asia / Tokyo', as follows.

└── Created directory
    └── laravel
        └── config
            └── app.php


    | Application Timezone
    | Here you may specify the default timezone for your application, which
    | will be used by the PHP date and date-time functions. We have gone
    | ahead and set this to a sensible default for you out of the box.

    'timezone' => 'Asia/Tokyo', //--Change this line

This completes the installation of Laravel.

Recommended Posts

Laravel + Docker Laradock usage environment construction
Docker environment construction
Build docker + laravel environment with laradock
Laravel development environment construction with Docker (Mac)
Environment construction with Docker (Ubuntu20.04) + Laravel + nginx
Laravel + MySQL + phpMyadmin environment construction with Docker
Rails Docker environment construction
MySQL 5.7 (Docker) environment construction memo
Redmine (Docker) environment construction memo
[Docker] Rails 5.2 environment construction with docker
Docker × Spring Boot environment construction
[Docker] postgres, pgadmin4 environment construction
Laravel environment construction (Ubuntu 18.04 LTS)
React environment construction with Docker
Rails + MySQL environment construction with Docker
[Portfolio] Manage site with laravel APP implementation (Docker environment construction)
Install laravel/Dusk in docker environment (laravel6)
Rails on Docker environment construction procedure
Create Laravel environment with Docker (docker-compose)
[Environment construction with Docker] Rails 6 & MySQL 8
SQL statement learning ~ Environment construction ~ Docker + MySQL
GPU environment construction with Docker [October 2020 version]
Rails environment construction with Docker (personal apocalypse)
Sapper × Go (echo) × Docker development environment construction
[Docker] Development environment construction Rails6 / Ruby2.7 / MySQL8
Spring Boot + Docker Java development environment construction
Docker + Laravel + Codeception
[Java] Environment construction
Java environment construction
[Spring] Environment construction
Docker + DynamoDB local + C ++ environment construction and practice
Just install Laravel8 on docker in PHP8 environment
Build a Laravel / Docker environment with VSCode devcontainer
Environment construction command memo with Docker on AWS
Kaggle environment construction using official Docker and vscode
Rails6 [API mode] + MySQL5.7 environment construction with Docker
A reminder of Docker and development environment construction
IntelliJ + Docker (APP + DB) + SpringBoot (Maven) environment construction
React + Django + Nginx + MySQL environment construction with Docker
Docker × Laravel HTTPS (SSL) communication in local environment
Wordpress local environment construction & development procedure with Docker
Penronse environment construction [Windows]
[Environment construction] Eclipse installation
[Flutter] Ubuntu 20.04 environment construction
BEAR application Docker development environment construction example (docker-sync, Mutagen)
Build Docker + Laravel PHP + Vue.js development environment in 5 minutes
Circle CI environment construction
java development environment construction
Docker container usage scene
Make the strongest Laravel development environment (Docker) Japan time
Database environment construction with Docker in Spring boot (IntellJ)
Construction of data analysis environment using Docker (personal memorandum)
Easy environment construction of MySQL and Redis with Docker and Alfred
Rails application development environment construction with Docker [Docker, Rails, Puma, Nginx, MySQL]
Pytorch execution environment with Docker
Rails6 development environment construction [Mac]
[Spring Boot] Environment construction (macOS)
WSL2 + VSCode + Docker development environment
Rails engineer environment construction ruby2.7.1
EC-CUBE4 environment construction (local edition)
[Docker] Create Elasticsearch, Kibana environment!