0
0

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】ARGの値を必須にする方法

0
Posted at

ARGの値を必須にする方法

Dockerfileに以下のように記述することでARGの値が渡されていない場合にエラーとすることができます。

Dockerfile

ARG SAMPLE_VARIABLE

RUN test -n "$EXAMPLE_VARIABLE"

SAMPLE_VARIABLEの中身が空の場合には以下のようなエラーが出てビルドが失敗します。

ターミナル
% docker build .
[+] Building 1.2s (5/7)                                                                                         
 => [internal] load build definition from Dockerfile                                                       0.0s
 => => transferring dockerfile: 620B                                                                       0.0s
 => [internal] load .dockerignore                                                                          0.0s
 => => transferring context: 2B                                                                            0.0s
 => [internal] load metadata for docker.io/library/node:16.17.0                                            0.9s
 => CACHED [1/5] FROM docker.io/library/node:16.17.0@sha256:0jfvaoifeojoa5fe64808ea28b49c5772b1026f81b3b716  0.0s
 => ERROR [2/5] RUN test -n "$EXAMPLE_VARIABLE"                                                                   0.2s
------
 > [2/5] RUN test -n "$EXAMPLE_VARIABLE":
------
executor failed running [/bin/sh -c test -n "$EXAMPLE_VARIABLE"]: exit code: 1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?