みなさん耄碌してますか?
私はもう耄碌してます。そうなるともう、つい昨日に叩いたちょっと長いコマンドラインなんて覚えていられなくなってしまいます。そのコマンドラインを実行するための前提条件とか、もう頭に入りきらないです。
別に耄碌してなくても、頭のメモリは空けておきたいですよね。
ちょっとしたコマンドの使い方をメモするのに Makefile
が便利だ、ということに気付いたので Qiitaに吐き出しておきます。
Makefileってなに?
ずっと前から存在しているビルドツール make のためのスクリプトファイルです。お使いのシェルに make と入力してみて、 command not found って怒られなければ使える環境が整ってます。こんな感じ:
all: default.css
default.css: default.scss
scss --style expanded default.scss:default.css
nginx:
docker run -d -v ~/www:/usr/share/nginx/html:ro -p 8080:80 nginx
作りたいもの: 材料 材料 材料...
作り方
作り方
:
コマンドラインのメモ書きとして使う
「docker で Webサーバ立てて wwwディレクトリを 8080/tcp で公開する」なんてのをコマンドラインで指定するときのオプションとか、長すぎて覚えられない。そこで、上記のように Makefile の「作り方」のところに書いておく。
nginx:
docker run -d -v ~/www:/usr/share/nginx/html:ro -p 8080:80 nginx
そして、思い出すとか、実行するとか。
matobaa@matobaa:~$ make -n nginx # -n をつけるとコマンドを表示する。実行しない
docker run -d -v ~/www:/usr/share/nginx/html:ro -p 8080:80 nginx
matobaa@matobaa:~$ make nginx # -n を外すと実行してくれる
docker run -d -v ~/www:/usr/share/nginx/html:ro -p 8080:80 nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
d34921bc2709: Pull complete
7062b3d97728: Pull complete
6ef91dbeea1d: Pull complete
5577be6571ad: Pull complete
5061d717b9a7: Pull complete
0ec95b15a374: Pull complete
7a6b73207086: Pull complete
bfdd4ced794e: Pull complete
Digest: sha256:dc53b036d0084d56d7957026c785762359620681096f405218c4cfb715012948
Status: Downloaded newer image for nginx:latest
3e764bed08e2670225f463019562c1116019a2316230d86bf748322abc2d3f3b
matobaa@matobaa:~$
前提条件があるときは「材料」のところにリストアップしておけば、「材料がないから実行できないよ!」とか指摘してくれる。便利!
TODO
- 整っていない場合の導入方法を書く。brewとかyumとかapt-getとか
- Windows での導入方法 → https://qiita.com/tokikaze0604/items/e13c04192762f8d4ec85