34
30

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 5 years have passed since last update.

Dockerのコマンドが長いのでalias設定した

Posted at

Docker コマンドが長い!

Docker コマンドをタイプする機会がたくさんあります。
毎回毎回、 docker から書き始めているとたいへんなので、
alias を設定して素早くコマンドを使えるようにしています。

alias 設定内容

alias d='docker'
alias dc='docker-compose'
alias dcnt='docker container'
alias dcur='docker container ls -f status=running -l -q'
alias dexec='docker container exec -it $(dcur)'
alias dimg='docker image'
alias drun='docker container run --rm -d'
alias drunit='docker container run --rm -it'
alias dstop='docker container stop $(dcur)'

これらを ~/.bash_profile に書いています。

Before / After

コンテナを起動するとき

Before:

docker image pull httpd
docker container run --rm -d -p 8000:80 httpd

After:

dimg pull httpd:latest
drun -p 8000:80 httpd:latest

シェルを実行するとき

Before:

docker image pull centos
docker container run --rm -it centos bash

After:

dimg pull centos
drunit centos bash

コンテナを止めるとき

Before:

docker container ls

... 止めたいコンテナのIDをコピー ...

docker container stop コピーしたコンテナのID

After:

dstop

docker-compose でサービスを立ち上げるとき

Before:

docker-compose up -d

After:

dc up -d

docker-compose でサービスを停止するとき

Before:

docker-compose down

After:

dc down
34
30
4

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
34
30

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?