Create Laravel environment with Docker (docker-compose)

at first

Refer to the one that was originally made (Paku)

Created like this

-Created with the image of php7.4 / mysql8 / nginx1.19 ・ Created with the project name sampleproject ・ Confirm with Docker Desktop for Windows

Folder structure

laravel
 ├ docker-compose.yml
 ├ docker
 │  ├ php
 │  │  ├ php.ini
 │  │  └ Dockerfile
 │  └ nginx
 │    └ default.conf
 └ server

Contents of each file

docker-compose.yml


version: '3'

services:
  laravel_php:
    container_name: laravel_php
    build: ./docker/php
    volumes:
    - ./server:/var/www

  laravel_nginx:
    image: nginx:1.19
    container_name: laravel_nginx
    ports:
    - 80:80
    volumes:
    - ./server:/var/www
    - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
    - laravel_php

  laravel_db:
    image: mysql:8.0
    container_name: laravel_db
    environment:
      MYSQL_ROOT_PASSWORD: rootpass
      MYSQL_DATABASE: sampleproject
      MYSQL_USER: dbuser
      MYSQL_PASSWORD: dbpass
      TZ: 'Asia/Tokyo'
    command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    volumes:
    - ./docker/db/data:/var/lib/mysql
    - ./docker/db/my.cnf:/etc/mysql/conf.d/my.cnf
    - ./docker/db/sql:/docker-entrypoint-initdb.d
    ports:
    - 3306:3306

../docker/nginx/default.conf


[Date]
date.timezone = "Asia/Tokyo"
[mbstring]
mbstring.internal_encoding = "UTF-8"
mbstring.language = "Japanese"

../docker/php/Dockerfile


FROM php:7.4-fpm
COPY php.ini /usr/local/etc/php/

RUN apt-get update && apt-get -y upgrade
RUN apt-get install -y zlib1g-dev && apt-get install -y libzip-dev
RUN docker-php-ext-install pdo_mysql zip

COPY --from=composer /usr/bin/composer /usr/bin/composer
ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_HOME /composer
ENV PATH $PATH:/composer/vendor/bin

WORKDIR /var/www

RUN composer global require "laravel/installer"

../docker/nginx/default.conf


server {
    index index.php index.html;
    server_name localhost;
    root /var/www/sampleproject/public;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass laravel_php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

Execution command

1. 1. Container construction

docker-compose up -d

2. 2. Laravel project creation

docker exec -ti laravel_php bash

In the container (version 6 creation command)

composer create-project "laravel/laravel=6.*" sampleproject

After creating the project (inside the container)

cd sampleproject
chmod -R 777 storage
chmod -R 777 bootstrap/cache
php artisan serve

3. 3. DB related

Edit .env (under project folder)

..env


DB_CONNECTION=mysql
DB_HOST=laravel_db
DB_PORT=3306
DB_DATABASE=sampleproject
DB_USERNAME=dbuser
DB_PASSWORD=dbpass

Connection confirmation

php argisan migrate

Recommended Posts

Create Laravel environment with Docker (docker-compose)
Create a Vue3 environment with Docker!
Create SolrCloud verification environment with Docker
Build docker + laravel environment with laradock
Create Rails 6 + MySQL environment with Docker compose
Create a MySQL environment with Docker from 0-> 1
Create Spring Boot-gradle-mysql development environment with Docker
[Docker] Create Node.js + express + webpack environment with Docker
Laravel + MySQL + phpMyadmin environment construction with Docker
[Memo] Create a CentOS 8 environment easily with Docker
Create a Spring Boot development environment with docker
Pytorch execution environment with Docker
[Docker] Create Elasticsearch, Kibana environment!
Deploy with EC2 / Docker / Laravel
[Docker] Rails 5.2 environment construction with docker
Build docker environment with WSL
React environment construction with Docker
Create an E2E test environment with Docker x Cypress
[Note] Create a java environment from scratch with docker
Create Chisel development environment with Windows10 + WSL2 + VScode + Docker
Rails + MySQL environment construction with Docker
Node.js environment construction with Docker Compose
Build Couchbase local environment with Docker
Build a Node.js environment with Docker
Let's create Ubuntu environment with vmware
Environment construction with Docker for beginners
Create RUNTEQ's environment with Windows DockerDesktop
Laravel + Docker Laradock usage environment construction
Build PlantUML environment with VSCode + Docker
Build environment with vue.js + rails + docker
[Portfolio] Manage site with laravel APP implementation (Docker environment construction)
General error: 1812 occurs with docker + laravel
Build Rails environment with Docker Compose
Install laravel/Dusk in docker environment (laravel6)
[Environment construction with Docker] Rails 6 & MySQL 8
Create Rails5 and postgresql environment with Docker and make pgadmin available
I tried to create a padrino development environment with Docker
Create a web environment quickly using Docker
Alert slack with alert manager in Docker environment
GPU environment construction with Docker [October 2020 version]
Rails environment construction with Docker (personal apocalypse)
Building Rails 6 and PostgreSQL environment with Docker
Build and manage RStudio environment with Docker-compose
Edit Mysql with commands in Docker environment
Build a Wordpress development environment with Docker
Display API specifications with Laravel + SwaggerUI + Docker
Build Nuxt TypeScript + Vuetify environment with docker-compose
[Docker] Build Jupyter Lab execution environment with Docker
Build an environment with Docker on AWS
Create external (URL) monitoring with Docker + Prometheus
Lightweight PHP 7.4 development environment created with Docker
Build TensorFlow operation check environment with Docker
Install Docker and create Java runtime environment
How to build Rails 6 environment with Docker
Docker + Laravel + Codeception
[Copy and paste] Build a Laravel development environment with Docker Compose Participation
Docker environment construction
Create a java web application development environment with docker for mac part2
Command line that can create a directory structure for building a Laravel environment with Docker in one shot
Spring Boot environment construction with Docker (January 2021 version)
Make SpringBoot1.5 + Gradle4.4 + Java8 + Docker environment compatible with Java11