這個工具是 Laravel 官方所提供使用 docker 作為本地開發環境的 image,這邊紀錄一下關於相關配置和安裝設定。我本地端還是有配置 Laravel Valet,所以很顯然的是我必須調整 port 和相關兼容避免 port aleady in use。
先決配置
- Docker
困難修復
- 開啟 Docker desktop/Resources/WSL integration/Ubuntu (我這邊 WSL 配置 Ubuntu)
- 進入 Ubuntu 內配置
$ sudo vi /etc/resolv.conf
配置 google nameserver:
nameserver 8.8.8.8
安裝步驟
- 從遠端取得對應 shell script,並且執行
$ curl -s "https://laravel.build/<你的專案名稱>" | bash
# curl -s "https://laravel.build/example-app" | bash
- 執行完畢後 cd 進去
- 開始配置對應 port ->
.env
,相關對應變數名稱可以參考docker-compose.yml
:
APP_PORT=8088 # http port
FORWARD_DB_PORT=33062 # db port
FORWARD_MAILPIT_PORT=1026 # mailpit
FORWARD_MAILPIT_DASHBOARD_PORT=8026 # mailpit dashboard
FORWARD_REDIS_PORT=6380 # redis
- 拜訪
http://localhost:8088
- 測試相關對應數據庫連線,查看對應
.env
DB_USERNAME=sail
DB_PASSWORD=password
- running docker
$ ./vendor/bin/sail up -d --build
# --build Build images before starting containers.
# -d, --detach Detached mode: Run containers in the background
- 連入 app container 進行 composer 指令操作
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9463d63df32b sail-8.2/app "start-container" 16 minutes ago Up 16 minutes 0.0.0.0:5173->5173/tcp, 8000/tcp, 0.0.0.0:8088->80/tcp l10-app-laravel.test-1
785445edb22d mysql/mysql-server:8.0 "/entrypoint.sh mysq…" 16 minutes ago Up 16 minutes (healthy) 33060-33061/tcp, 0.0.0.0:33062->3306/tcp l10-app-mysql-1
c5194fdad648 seleniarm/standalone-chromium "/opt/bin/entry_poin…" 16 minutes ago Up 16 minutes 4444/tcp, 5900/tcp l10-app-selenium-1
a64d1c6ae871 redis:alpine "docker-entrypoint.s…" 16 minutes ago Up 16 minutes (healthy) 0.0.0.0:6380->6379/tcp l10-app-redis-1
d39770a3a880 getmeili/meilisearch:latest "tini -- /bin/sh -c …" 16 minutes ago Up 16 minutes (healthy) 0.0.0.0:7700->7700/tcp l10-app-meilisearch-1
f978a7789510 axllent/mailpit:latest "/mailpit" 16 minutes ago Up 16 minutes 0.0.0.0:1026->1025/tcp, 0.0.0.0:8026->8025/tcp l10-app-mailpit-1
$ ./vendor/bin/sail artisan migrate
# $ docker exec 9463d6 --bash
有了這個工具之後可以在測試新版本或是嘗試性的動作時相當方便,或是當成隔離開發環境使用。