@ ucan-lab's [Docker x Laravel makes Docker for Mac explode](https://qiita.com/ucan-lab/items/ Proposal 4 of a88e2e5c2a79f2426163) was verified on Windows 10.
Proposal 4. Use volume mount
-[JavaScript] How to make npm / yarn operation on Docker 10 times faster
A plan to store vendor and node_modules data in a named volume and manage it separately from the host side and container side. Since synchronization processing does not occur, it will be faster.
Add the volume mount settings to docker-compose.yml and compare the composer and npm installations. This article will not touch on why it is faster.
We are comparing the speeds of composer install
and npm install
respectively.
$ time composer install
real 6m26.446s -> 0m57.445s # 6.7 times
user 0m9.375s -> 0m3.035s
sys 0m51.148s -> 0m1.544s
$ time npm install
real 1m31.764s -> 0m22.720s # 4.0 times
user 0m46.022s -> 0m23.705s
sys 0m32.465s -> 0m13.917s
It's 4-7 times faster in Windows 10 environment! It wasn't 20 times as fast as the referrer Mac, but I'm happy that it's fast enough with just a few lines added!
--Windows 10 Home version 2004 (OS build 19041.508)
The following article will be helpful for building the environment. Windows Subsystem for Linux Installation Guide for Windows 10 Using WSL 2 + Docker on Windows 10 Home | Qiita
Validate using Laravel + Nginx + MySQL development environment. For details, see Blog.
composer and package.json are in the state from project creation to installation of Inertia of laravel / jetstream.
The speed is compared with and without the comment ʻadd` line.
version: '3'
volumes: # add
vendor-store: # add
node_modules-store: # add
services:
php:
container_name: php
build: ./docker/php
volumes:
- ./web:/var/www
- vendor-store:/var/www/laravel/vendor # add
- node_modules-store:/var/www/laravel/node_modules # add
environment:
TZ: Asia/Tokyo
nginx:
image: nginx
container_name: nginx
ports:
- 80:80
volumes:
- ./web:/var/www
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
db:
image: mysql:8.0
container_name: db
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: database
MYSQL_USER: docker
MYSQL_PASSWORD: docker
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
The execution procedure is the same as the reference source. Please read the path.
Recommended Posts