Build a SPA for Laravel 6.2 / Vue.js / Nginx / Mysql / Redis with Docker

What is Docker

It has been a long time since the usefulness of Docker and the usefulness of SPA (Single Page Application) have been emphasized, and I think that Docker / SPA has become quite popular these days. Docker creates a virtual environment for running web applications such as Laravel, and this Docker environment can also be deployed in production. This time, let's create a PHP + Vue.js SPA with Laravel on Docker.

Docker-comppse is a so-called orchestration tool that creates and manages multiple Docker images.

Docker installation

First, install Docker.

  1. Windows users should use Docker for Windows. If you are using Windows 7 or something, you may be able to use Docker toolbox (note that toolbox is Deprecated)
  2. Mac users should use Docker for Mac.
  3. An Ubuntu 18 user like me installs as follows: First, erase the old Docker.
$ sudo apt-get remove docker docker-engine docker.io

Then install from the official repository.

$ sudo apt-get update
# To enable https connection.
$ sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
# To download GPG key.
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# Install the docker repository.
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu  $(lsb_release -cs)  stable" 
$ sudo apt-get update
# Install Docker.
$ sudo apt-get install docker-ce

Check if Docker was installed successfully

Let's check if Docker has been installed successfully. If you type the following command on the terminal and the version is displayed, it is successful.

docker --version
#Docker version 19.03.5, build 633a0ea838

It is OK if the version can be displayed like this.

Also check Docker-compose

Docker-compose should have been installed along with the Docker installation. Check with the following command. If the version is displayed, it is successful.

docker-compose -v
#docker-compose version 1.24.1, build 4667896b

Try using Docker and Docker-compose

Drop the docker-compose file from my git repository and run it with the following command.

$ git clone https://github.com/lechatthecat/laravel-coreuivue-integration
$ cd laravel-coreuivue-integration
$ docker-compose up -d --build
$ docker-compose exec laravel ash
$ ash ./laravel_build.sh

Then you can see that Core UI vue is running locally. http://localhost:10080/

However, since it was troublesome, I only made the dashboard and login pages properly. Click here for a proper demo page. https://coreui.io/vue/demo/3.1.0/#/dashboard

Since it is an MIT license, it can be used for commercial purposes if the rights are properly displayed. Screenshot from 2020-11-11 23-27-46.png

docker compose config file

The docker-compose file dropped from Git has these settings. You can see that you are using Nginx / Mysql / Redis properly.

version: "3.5"
#Used when sharing volume between containers
x-services-volume:
  &laravel-volume
  type: bind
  source: ./laravel-coreui
  target: /laravel-coreui

services:
  laravel:
    container_name: laravel
    depends_on:
      - mydb
      - myredis
    build:
      context: .
      dockerfile: docker/laravel/Dockerfile
      args:
        - TZ=${TZ}
    # bind mount
    volumes:
      - <<: *laravel-volume
      - ./docker/laravel/laravel_build.sh:/laravel-coreui/laravel_build.sh
      - ./logs:/var/log/php
      - ./docker/laravel/php.ini:/usr/local/etc/php/php.ini
    working_dir: /laravel-coreui
    environment:
      - DB_CONNECTION=mysql
      - DB_HOST=db
      - DB_DATABASE=${DB_NAME}
      - DB_USERNAME=${DB_USER}
      - DB_PASSWORD=${DB_PASSWORD}
      - TZ=${TZ}
    networks:
      - app_net
  # nginx 1.17
  web:
    container_name: my_nginx
    image: nginx:1.17-alpine
    depends_on:
      - laravel
    ports:
      - 10080:80
    volumes:
      - *laravel-volume
      - ./logs:/var/log/nginx
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:z
    environment:
      - TZ=${TZ}
    networks:
      - app_net
  # MySQL 8.0
  mydb:
    container_name: mydb
    image: mysql:8.0
    volumes:
      - db-store:/var/lib/mysql
      - ./logs:/var/log/mysql:z
      - ./docker/mysql/my.cnf:/etc/mysql/conf.d/my.cnf:z
    ports:
      - 13306:3306
    environment:
      - MYSQL_DATABASE=${DB_NAME}
      - MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
      - MYSQL_USER=${DB_USER}
      - MYSQL_PASSWORD=${DB_PASSWORD}
      - TZ=${TZ}
    networks:
      - app_net
  # redis 5.0.5 
  myredis:
    container_name: myredis
    image: redis:5.0.5-alpine
    # bind mount
    volumes:
      - redis-store:/data
      - ./logs:/var/log/redis.log:z
      - ./docker/redis/my.conf:/etc/redis/my.conf:z
    ports:
      - 16379:6379
    command: redis-server /etc/redis/my.conf
    networks:
      - app_net
networks:
    # Containers in same network can access each other by using its container name as host name
    app_net:
        driver: "bridge"
volumes:
  db-store:
  redis-store:

Recommended Posts

Build a SPA for Laravel 6.2 / Vue.js / Nginx / Mysql / Redis with Docker
Build a development environment for Django + MySQL + nginx with Docker Compose
Build a Laravel / Docker environment with VSCode devcontainer
Build a container for Docker x Laravel phpMyAdmin
Easily build a Vue.js environment with Docker + Vue CLI
Build a web application development environment that uses Java, MySQL, and Redis with Docker CE for Windows
Build a Node.js environment with Docker
Build environment with vue.js + rails + docker
Build docker + laravel environment with laradock
Procedure for building a Rails application development environment with Docker [Rails, MySQL, Docker]
Build a PureScript development environment with Docker
Environment construction with Docker (Ubuntu20.04) + Laravel + nginx
Create a MySQL environment with Docker from 0-> 1
[docker] [nginx] Make a simple ALB with nginx
Laravel + MySQL + phpMyadmin environment construction with Docker
Build a Wordpress development environment with Docker
[Copy and paste] Build a Laravel development environment with Docker Compose Part 2
Build a local development environment for Rails tutorials with Docker (Rails 6 + PostgreSQL + Webpack)
[Copy and paste] Build a Laravel development environment with Docker Compose Participation
Build a development environment for Docker + Rails6 + Postgresql
Build a WordPress development environment quickly with Docker
React + Django + Nginx + MySQL environment construction with Docker
Build a development environment for Docker, java, vscode
A simple CRUD app made with Nuxt / Laravel (Docker)
How to build docker environment with Gradle for intelliJ
Build Docker + Laravel PHP + Vue.js development environment in 5 minutes
Build a local development environment for Open Distro for Elasticsearch with multiple nodes using Docker
[Note] Build a Python3 environment with Docker in EC2
[Note] I suddenly can't build with Docker for windows.
How to quit Docker for Mac and build a Docker development environment with Ubuntu + Vagrant
(For myself) Build gitlab with ubuntu18.04 + docker for home (Note)
[Docker] Connection with MySQL
How to make Laravel faster with Docker for Mac
Build Rails (API) x MySQL x Nuxt.js environment with Docker
Build an Android image for Orange Pi 4 with Docker
[2021] Build a Docker + Vagrant environment for using React / TypeScript
(For myself) Build an IDE that you can touch from a browser with docker (trial)
How to build [TypeScript + Vue + Express + MySQL] environment with Docker ~ Express ~
Easy environment construction of MySQL and Redis with Docker and Alfred
Rails application development environment construction with Docker [Docker, Rails, Puma, Nginx, MySQL]
Build a container that automatically formats Docker x Laravel code
Build a Node-RED environment with Docker to move and understand
Measures for permissions when building MySQL with Docker on WSL2
Deploy with EC2 / Docker / Laravel
Build docker environment with WSL
Build DynamoDB local with Docker
One file of Docker x Laravel threat! Build a local development environment with the minimum configuration
Build Metabase with Docker on Lightsail and make it https with nginx
Build apache7.4 + mysql8 environment with Docker (with initial data) (your own memo)
How to build [TypeScript + Vue + Express + MySQL] environment with Docker ~ MySQL edition ~
(For myself) Try creating a C # environment with docker + code-server, cloud9
Create a flyway jar with maven and docker build (migrate) with docker-maven-plugin
How to build Rails + Vue + MySQL environment with Docker [2020/09 latest version]
"Rails 6 x MySQL 8" Docker environment construction procedure for sharing with teams
How to build [TypeScript + Vue + Express + MySQL] environment with Docker ~ Sequelize ~
I tried to build a laravel operating environment while remembering Docker
Command line that can create a directory structure for building a Laravel environment with Docker in one shot
Rails + MySQL environment construction with Docker
Deploy a Docker application with Greengrass
Build Couchbase local environment with Docker
Build a Java project with Gradle