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.

文字列をARGに設定したらよくわからない値になった時の対応方法

Posted at
  • 環境
    • CentOS Linux release 7.8.2003 (Core)
    • Docker Engine Version: 19.03.8
    • docker-compose version 1.25.5

docker-compose.ymlで「0」始まりの文字列をARGに設定したらよくわからない値になった

docker-compose.ymlで「0」始まりの数字文字列「06000001」をARGに設定して、

docker-compose.yml
version: '3.8'
services:
  app-java11:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        my_code: 06000001
...省略...

Dockerfile内でsedするのに使った・・・

Dockerfile
FROM centos:centos7.7.1908
# ...省略...
ARG my_code

COPY app/domain.xml payara5/glassfish/domains/domain1/config/
RUN sed -i -e "s/{{my_code}}/${my_code}/g" payara5/glassfish/domains/domain1/config/domain.xml
# ...省略...

結果「06000001」ではなく「1572865」というわからない値になった

$ docker-compose up -d --no-recreate --build
# ...省略...
Creating app-java11 ... done
$ docker exec -it app-java11 bash
# grep files /opt/payara5/glassfish/domains/domain1/config/domain.xml
        <jvm-options>-Dapp.resources.dir=/var/app/files/1572865</jvm-options>

原因 : シングルクォーテーションで囲んでないから

ダブルクォーテーションでもOK。
気が付けば普通だが気が付くのに時間がかかった。

対応方法 : 文字列をシングルクォーテーションで囲む

docker-compose.yml
...省略...
      args:
        my_code: '06000001'
...省略...
$ docker-compose up -d --no-recreate --build
# ...省略...
Creating app-java11 ... done
$ docker exec -it app-java11 bash
# grep files /opt/payara5/glassfish/domains/domain1/config/domain.xml
        <jvm-options>-Dapp.resources.dir=/var/app/files/06000001</jvm-options>
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?