5
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.

docker-composeの後につくbash,ashの違い

Posted at

仕事で利用している開発環境では、、、

docker-compose exec -it <container> bash

なんだけど、自分が個人開発で使っているものは、

docker-compose exec -it <contaienr> ash

でした。
bashで使っている環境のコマンドはashにするとエラーになるし、もう一方も同じ。

これってどんな違いがあるのかな?と思い調べてみました。

TL;DR

dockerコンテナ内部でシェルを使う時の参照元の違い

詳細

言わずもがなではありますが、シェルはOS(Linux)を操作するCUIのことです。
開発を行うにあたってはdockerコンテナに入ってから色々コマンドを打つわけですが、そのコマンドを打つためにbashを参照しています。

bashの中には「pwdというコマンドが送られてきたら現在のパスを表示する」みたいなコマンドが登録されていて、シェルが実行できるワケですね。

ただ、同じLinuxでもディストリービューションによってシェルの置き場所がbashではない場合があります。

それを確認できるのが下記のコマンド。

echo $SHELL
// /bin/bash or /bin/ash

bashでコンテナに入れるdockerコンテナ内で打った時は/bin/bash
ashで入れる場合は/bin/ashになります。

いわゆる「パスを通す」みたいなコトをdocker-composeでもやっています。

LinuxやDockerのキホンを知らなかったコトをさらけ出しただけのような気もしますが、スッキリしました!

参考資料

下記記事が分かりやすく、とても助かりました!

dockerでalpine linux ベースのcontainerに入って、shellを使いたいとき。

【Docker-Compose】コンテナ起動から入るまでを丁寧に

5
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
5
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?