0
2

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-compose.ymlをコマンドラインで使う

Last updated at Posted at 2020-09-24

独自のdocker-compose.yml

プロジェクトのdocker-compose.ymlを独自に書き変えたい場合

docker-compose -f docker-compose.myenv.yml

-fオプションにカスタマイズしたYAMLファイルを指定することで、独自のCompose設定ファイルをもとにコマンドが実行されます。

しかし、毎回指定するのは面倒ですよね。

シェルの設定ファイル

.bashrcなどに以下を追記することで、ディレクトリ直下に独自の設定ファイルがある場合、dcを実行するとdocker-compose.myenv.ymlが適用されます。

.bashrc
function dc() {
    if [[ -f docker-compose.myenv.yml ]]; then
        echo 'Using docker-compose.myenv.yml'
        docker-compose -f docker-compose.myenv.yml $@
    else
        docker-compose $@
    fi;
}
alias dc=dc

.docker-compose.myenv.ymlがあるとき
$ dc
Using docker-compose.myenv.yml
Define and run multi-container applications with Docker.
...
0
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?