docker-compose args from shell

随声附和 提交于 2020-06-11 02:59:46

问题


I want to build via the docker-compose an image that uses my private key for cloning private git repos.

More or less the compose becomes as follows:

   myservice:
     build:
      context: .
      args:
        RSA:  ~/.ssh/id_rsa

The above does not work, neither the following:

   myservice:
     build:
      context: .
      args:
        RSA: $(cat ~/.ssh/id_rsa)

The docker build command works just fine however in the form of

docker build --build-args RSA=$(cat ~/.ssh/id_rsa) -t myservice:latest

回答1:


You can use the same syntax with docker-compose build:

docker-compose build --build-args RSA=$(cat ~/.ssh/id_rsa)

Unfortunately, you can't use the build-args option with compose up or start... So you will need to build and then run using the --no-build option




回答2:


One way to do it that will work when building all the services and also with up is to pass the SSH key data as an environnement variable like this:

env RSA=$(cat ~/.ssh/id_rsa) docker-compose build

And then you set the build args in the compose file like this:

myservice:
 build:
  context: .
  args:
    RSA: |-
      ${RSA}



回答3:


add ARGS in your Dockerfile like

ARGS RSA

For it to be read upon build



来源:https://stackoverflow.com/questions/47390515/docker-compose-args-from-shell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!