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

Dockerfileでの|(パイプ)の扱い

Last updated at Posted at 2020-08-13

hadolint DL4006について

Set the SHELL option -o pipefail before RUN with a pipe in

DockerfileのRUN命令の前に、SHELL命令で、-o pipefailを指定しておくべしというもの

なぜつけた方がいいのか?

example(ダメな例)
RUN wget -O - https://some.site | wc -l > /number

上の例では、wc -lコマンドが成功している限り、wgetコマンドが失敗しても、このビルドステップは成功して新しいイメージを生成します。

そこでSHELL命令の出番

example(良い例)
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN wget -O - https://some.site | wc -l > /number

bash -o pipefail / set -o pipefail

パイプでつないだ各コマンドの中で終了ステータスが0以外(正常終了以外)だった場合に、最後に0以外だったコマンドの終了ステータスが返されます。

すなわちwgetコマンドが失敗した場合に、ビルドが成功しないようになるということです

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