0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laravel sail

Last updated at Posted at 2021-07-04

環境

Mac OS Catalina 10.15.7
Docker 20.10.6

Laravel Sailとは

Laravelが公式に提供しているDocker開発環境。
Laravelの開発環境を簡易に構築可能。
PHP、ビルトインWebサーバー、MySQL、キャッシュ向けミドルウェアのRedis、
簡易メールサーバーのMailhog、Selenium、Nodeなどを含む。

Dockerをインストール

インストール済みなので省略

Laravel Sailをダウンロード

好きなところに、ダウンロード先のディレクトリを作成

$ mkdir laravel_docker

curlコマンドを利用して、Laravel Sailをダウンロード

$ curl -s https://laravel.build/sample | bash

途中、パスワードを求められるので、端末のパスワードを入力

Application ready! Build something amazing.
Sail scaffolding installed successfully.

Please provide your password so we can make some final adjustments to your application's permissions.

Password:

下記のメッセージが出ればダウンロード完了

Thank you! We hope you build something incredible. Dive in with: cd sample && ./vendor/bin/sail up

Laravel Sail

ダウンロードしたディレクトリに移動して、起動する

$ cd sample
$ ./vendor/bin/sail up -d
Docker Compose is now in the Docker CLI, try `docker compose up`

Creating network "sample_sail" with driver "bridge"
Creating sample_redis_1       ... done
Creating sample_selenium_1    ... done
Creating sample_mysql_1       ... done
Creating sample_meilisearch_1 ... done
Creating sample_mailhog_1      ... done
Creating sample_laravel.test_1 ... done

http://localhost/
にアクセスして、下記が表示されればOK
スクリーンショット 2021-07-04 18.50.54.png

エイリアス登録

コマンドを打つのは面倒なので、エイリアス登録しておくと便利

$ cd $HOME
$ vim ~/.zshrc
~/.zshrc
alias sail="./vendor/bin/sail"

ターミナルを再起動するか、下記コマンドで変更を反映

source ~/.zshrc

コンテナ起動

コンテナを起動

$ sail up

コンテナをバックグラウンドで起動

$ sail up -d

コンテナ接続

$ sail shell
sail@09ba62631a2f:/var/www/html$ 

実行中のコンテナ一覧

$ sail ps
        Name                       Command                  State                                             Ports                                       
----------------------------------------------------------------------------------------------------------------------------------------------------------
sample_laravel.test_1   start-container                  Up             0.0.0.0:80->80/tcp,:::80->80/tcp, 8000/tcp                                        
sample_mailhog_1        MailHog                          Up             0.0.0.0:1025->1025/tcp,:::1025->1025/tcp, 0.0.0.0:8025->8025/tcp,:::8025->8025/tcp
sample_meilisearch_1    tini -- /bin/sh -c ./meili ...   Up (healthy)   0.0.0.0:7700->7700/tcp,:::7700->7700/tcp                                          
sample_mysql_1          docker-entrypoint.sh mysqld      Up (healthy)   0.0.0.0:3306->3306/tcp,:::3306->3306/tcp, 33060/tcp                               
sample_redis_1          docker-entrypoint.sh redis ...   Up (healthy)   0.0.0.0:6379->6379/tcp,:::6379->6379/tcp                                          
sample_selenium_1       /opt/bin/entry_point.sh          Up             4444/tcp      

MySQLへ接続

$ sail mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.25 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

コンテナ終了

$ sail down

参考

PHPフレームワーク Laravel Webアプリケーション開発

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?