Hướng dẫn cài đặt docker laravel - lemp
Kéo xuống dưới, chọn 1 trong 2 phiên bản: Stable version – bản ổ định và Edge Version – Bản dev Tải về file docker.dmg rồi Open file để cài đặt. Đơn giản, bạn chỉ cần kéo thả biểu tượng con cá voi sang bên biểu tượng thư mục.
I Cài đặt docker trên mac os
Để cài đặt được Docker trên mac, bạn chỉ cần truy cập trang sau:
https://docs.docker.com/docker-for-mac/install/#download-docker-for-mac

Kéo xuống dưới, chọn 1 trong 2 phiên bản: Stable version – bản ổ định và Edge Version – Bản dev
Tải về file docker.dmg rồi Open file để cài đặt. Đơn giản, bạn chỉ cần kéo thả biểu tượng con cá voi sang bên biểu tượng thư mục.
Cài đặt trên ubuntu
B1: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - B2: apt-key fingerprint 0EBFCD88 B3: add-apt-repository "deb[arch=amd64]https://download.docker.com/linux/Ubuntu $(lsb_release -cs)\stable" B4: apt-get install docker-ce B6: curl –L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose B7: chmod +x /usr/local/bin/docker-compose
hoặc
apt-get install docker docker-compose
II Tạo file
2 Tạo file docker-compose.yml
version: '3'
services:
blog-server:
image: daolamsoncntt/php:7.2
depends_on:
- mysql
- redis
volumes:
- ./:/var/www/html/:cached
horizon:
image: daolamsoncntt/php:7.2
command: php artisan horizon
depends_on:
- mysql
volumes:
- ./:/var/www/html/:cached
mysql:
image: mysql:5.7
ports:
- "33060:3306"
environment:
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_DATABASE=laravel-blog
volumes:
- ./storage/tmp/db:/var/lib/mysql:cached
nginx:
image: nginx:latest
ports:
- "8090:80"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf:cached
- ./:/var/www/html/:cached
depends_on:
- blog-server
redis:
image: redis
ports:
- "63791:6379"
Tạo file cấu hình nginx nginx.conf
server {
listen 80;
index index.php index.html index.htm;
root /var/www/html/public; # default Laravel's entry point for all requests
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_index index.php;
fastcgi_pass blog-server:9000; # address of a fastCGI server
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
}
Nếu bạn muốn thay đổi version php bạn thay đổi image: daolamsoncntt/php:7.2 thành các version mong muốn. ví dụ image: daolamsoncntt/php:7.1, image: daolamsoncntt/php:7.0, image: daolamsoncntt/php:5.6.
Thay đổi version Mysql bạn thay đổi đoạn image: mysql:5.7 thành các version mong muốn. ví dụ image: mysql:5.7, image: mysql:5.6 ....
Bạn tạo 2 file và thư mục của project
Tiếp theo chạy chạy tạo image và container bằng docker-compose ( thêm -d nếu bạn muốn chạy ngầm)
docker-compose up -d