0
0

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.

Docker ふたつの方法で環境構築時のコマンド群をまとめる

0
Last updated at Posted at 2022-02-16

概要

  • dockerを使ったローカル開発環境の構築だとしても、いくつかのコマンドを実行する必要がある。その手間を2つのアプローチでコマンドをまとめて解決してみようと思う

完成したもの

前提

まとめたいコマンド

  • 今回例に上げるlaravelのローカル開発環境構築時にgit cloneとは別に下記のコマンド実行が必要になる。

    $ docker-compose up -d --build
    $ docker-compose exec php composer install
    $ docker-compose exec php cp .env.example .env
    $ docker-compose exec php php artisan key:generate
    $ docker-compose exec php php artisan migrate
    
  • 上記5コマンドを一つにまとめたい。

方法その1 (shellスクリプトの使用)

  1. docker-compose.ymlファイルと同じ階層に下記のshellスクリプトファイルを用意する。

    install.sh
    #!/bin/bash
    
    docker-compose up -d --build
    docker-compose exec php composer install
    docker-compose exec php cp .env.example .env
    docker-compose exec php php artisan key:generate
    docker-compose exec php php artisan migrate
    
  2. 記載が終わったら下記コマンドを実行してinstall.shの権限を変更する。

    $ sudo chmod 755 install.sh
    
  3. 下記コマンドを実行してスクリプトファイルを実行する。(コマンドの最後の1>&2エラーも標準出力に出してくれるおまじないです。)

    $ ./install.sh 1>&2
    

方法その2 (Makefileの使用)

※こちらの知見は同じプロジェクトに参画されているエンジニアさんから教えていただいたものです。

  1. docker-compose.ymlファイルと同じ階層に下記のMakefileを用意する。

    .PHONY: install
    install:
    	docker-compose up -d --build
    	docker-compose exec php composer install
    	docker-compose exec php cp .env.example .env
    	docker-compose exec php php artisan key:generate
    	docker-compose exec php php artisan migrate
    
  2. 下記コマンドを実行する。

    $ make install
    
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?