[Copy and paste] Build a Laravel development environment with Docker Compose Part 2

Last time, I tried to build a Laravel environment with Docker Compose, but I had trouble handling Laravel. [Copy] Build Laravel development environment with Docker Compose

After all, I put it in a container and installed Laravel, but ... it's not good. As a result of thinking, I thought that Laravel should be managed in the repository together with docker-compose.yml and others. Yeah, maybe this is the best! I mean, there is only this! !!

Machine specs

Docker environment

things to do

Supplement

Since it goes back and forth between each environment, it is described as follows.

[Mac]$Working in a Mac with a Mac terminal
[PHP]$Work by connecting to a PHP container from a Mac terminal

Edit docker-compose.yml

https://github.com/bobtabo/docker/blob/master/docker-compose.yml

services:
  nginx:
・ ・ ・
    volumes:
      - ~/MountPoint/docker/home:/home/docker
・ ・ ・
  php:
・ ・ ・
    volumes:
      - ~/Work/MountPoint/docker/home:/home/docker
・ ・ ・
  db:
    volumes:
      - ~/Work/MountPoint/docker/db/data:/var/lib/mysql
・ ・ ・

The mount point was separated from the container files, but changed to the following to make it the same directory.

services:
  nginx:
・ ・ ・
    volumes:
      - ./src:/home/docker
・ ・ ・
  php:
・ ・ ・
    volumes:
      - ./src:/home/docker
・ ・ ・
  db:
    volumes:
      - ./db:/var/lib/mysql
・ ・ ・

Edit .gitignore

https://github.com/bobtabo/docker/blob/master/.gitignore

--No need to mount / var / lib / mysql. -No mount other than / home / docker / laravel is required.

/db
/src/*
!/src/laravel

Preparing for Laravel

The above is a template, but since it's a big deal, Laravel is also available. Since the PHP version of the Mac and the container are different, I work inside the container.

[Mac]$ docker-compose exec --user 1000 php bash

[PHP]$ composer create-project --prefer-dist laravel/laravel laravel "5.6.*"
[PHP]$ cd laravel
[PHP]$ composer require --dev barryvdh/laravel-ide-helper
[PHP]$ composer require --dev squizlabs/php_codesniffer
[PHP]$ mkdir bin
[PHP]$ vi bin/clear-laravel.sh
---
#!/bin/bash
php artisan view:clear
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan clear-compiled
php artisan config:cache
composer dump-autoload
php artisan ide-helper:generate
php artisan ide-helper:models -N
php artisan ide-helper:meta
find . -name '._.DS_Store' -type f -ls -delete
---
:wq
[PHP]$ vi .env.example
---
:%s/DB_HOST=127.0.0.1/DB_HOST=mysql/g
:%s/DB_DATABASE=homestead/DB_DATABASE=hoge/g
:%s/DB_USERNAME=homestead/DB_USERNAME=fuga/g
:%s/DB_PASSWORD=secret/DB_PASSWORD=docker#DOCKER1234/g
---
:wq

Complete! !! https://github.com/bobtabo/docker2

How to use

[Mac]$ cd <Arbitrary directory>
[Mac]$ git clone https://github.com/bobtabo/docker2.git docker
[Mac]$ cd docker
[Mac]$ docker-compose up -d
・ ・ ・
Creating mysql ... done
Creating php   ... done
Creating nginx ... done

[Mac]$ docker-compose exec --user 1000 php bash

[PHP]$ pwd
/home/docker

[PHP]$ cd laravel
[PHP]$ composer install
[PHP]$ chmod -R 777 storage
[PHP]$ chmod -R 777 bootstrap/cache
[PHP]$ cp -p .env.example .env
[PHP]$ php artisan key:generate
[PHP]$ chmod 755 bin/clear-laravel.sh
[PHP]$ bin/clear-laravel.sh
[PHP]$ php artisan migrate:fresh --seed

Recommended Posts

[Copy and paste] Build a Laravel development environment with Docker Compose Part 2
[Copy and paste] Build a Laravel development environment with Docker Compose Participation
[Rails] [Docker] Copy and paste is OK! How to build a Rails development environment with Docker
Build a Wordpress development environment with Docker
Build a development environment for Django + MySQL + nginx with Docker Compose
Build a WordPress development environment quickly with Docker
Build a simple Docker Compose + Django development environment
Build a Node.js environment with Docker
Build Rails environment with Docker Compose
Build docker + laravel environment with laradock
Build a Node-RED environment with Docker to move and understand
Until you build a Nuxt.js development environment with Docker and touch it with VS Code
How to quit Docker for Mac and build a Docker development environment with Ubuntu + Vagrant
Build a simple Docker + Django development environment
Build a development environment for Docker + Rails6 + Postgresql
One file of Docker x Laravel threat! Build a local development environment with the minimum configuration
Creating a java web application development environment with docker for mac part1
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
Build a local development environment for Rails tutorials with Docker (Rails 6 + PostgreSQL + Webpack)
[Win10] Build a JSF development environment with NetBeans
Prepare a scraping environment with Docker and Java
A reminder of Docker and development environment construction
Build a development environment for Docker, java, vscode
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
Template: Build a Ruby / Rails development environment with a Docker container (Ubuntu version)
[First team development ②] Build an environment with Docker
Create a java web application development environment with docker for mac part2
Template: Build a Ruby / Rails development environment with a Docker container (Mac version)
Create a Spring Boot development environment with docker
Build a Java development environment with VS Code
Build a web application development environment that uses Java, MySQL, and Redis with Docker CE for Windows
Build a Doker-based development environment on Windows 10 Home 2020 ver. Part 1 Until WSL2-based Docker build
Build a development environment to create Ruby on Jets + React apps with Docker
Easily build a Vue.js environment with Docker + Vue CLI
Build Docker + Laravel PHP + Vue.js development environment in 5 minutes
Build Java development environment with WSL2 Docker VS Code
[Environment construction] Build a Java development environment with VS Code!
Build WordPress environment with Docker (Local) and AWS (Production)
Try to build a Java development environment using Docker
Build docker environment with WSL
Install Ubuntu 20.04 in virtual box on windows10 and build a development environment using docker
Build a local development environment for Open Distro for Elasticsearch with multiple nodes using Docker
I made a development environment with rails6 + docker + postgreSQL + Materialize.
Build a "Spring Thorough Introduction" development environment with IntelliJ IDEA
How to build Rails, Postgres, ElasticSearch development environment with Docker
I tried to create a padrino development environment with Docker
Create a Vue3 environment with Docker!
Node.js environment construction with Docker Compose
Build Couchbase local environment with Docker
Build a Tomcat 8.5 environment with Pleiades 4.8
Build a local development environment for Rails tutorials with Docker-Introduce Bootstrap and Font Awesome with Webpack-
Build PlantUML environment with VSCode + Docker
Build environment with vue.js + rails + docker
Create Laravel environment with Docker (docker-compose)
Build jooby development environment with Eclipse
Copy and paste test with RSpec
Build Unity development environment on docker
Build Go development environment with WSL2 + Docker Desktop + VSCode (Remote --Containers)
Build a SPA for Laravel 6.2 / Vue.js / Nginx / Mysql / Redis with Docker
Procedure for building a Rails application development environment with Docker [Rails, MySQL, Docker]
Create a flyway jar with maven and docker build (migrate) with docker-maven-plugin