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

Dockerfile内で動的なENVの設定は出来なかった。

Last updated at Posted at 2020-08-14
RUN yum -y install java-11-openjdk java-11-openjdk-devel
ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk-11.0.8.10-0.el7_8.x86_64
ENV PATH $PATH:$JAVA_HOME/bin

こんな感じのDockerfile作ってたんだけど、yumでopenjdkインストールするとjava-11-openjdk-11.0.8.10-0.el7_8.x86_64の部分がVerUpごとに変わっちゃって、その度に修正しなきゃならないんだよね…。滅多にDockerImage更新することないからいいっちゃいいんだけど。
なので動的にENVの設定が出来ないかなあ?と思ってたんだけど、出来ないみたいだね。

RUN  export JAVA_HOME="$(dirname $(dirname $(readlink -f $(which java))))"

本当はこんな感じのことができればよかったんだけど。

セキュリティリスクだから駄目なのか。確かになー。
下みたいにすればいいよって書いてあるけど、Docker内でyumやってるから無理なんだよなこれ。

However, you can pass the information through a --build-arg (ARG) when building an image;

FROM busybox
ARG BUILD_HOST_NAME
ENV DOCKERBUILDHOST=${BUILD_HOST_NAME:-unkown}
RUN echo $DOCKERBUILDHOST

And build the image with;

docker build --build-arg BUILD_HOST_NAME=$(hostname) .

Or, if you want to copy information from an existing env-var on the host;

export BUILD_HOST_NAME=foobar
docker build --build-arg BUILD_HOST_NAME .

他も調べてみた。

AWSのCodeBuildイメージはCoretto11なので、ディレクトリ固定。
https://github.com/aws/aws-codebuild-docker-images

まあこの場合だけの話であれば、普通はFROM adoptopenjdk/openjdk11:latestとしとけば良いだけだけどねえ。

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