如何将Env/Build Arg从Docker-Compose脚本传递到Dockerfile入口处命令?
我想将env/build var传递给我的dockerfile,以便在其入口处使用,并认为我可以从docker-compose文件中这样做,因此
web:
restart: "no"
build:
context: ../my-project
args:
CURRENT_ENV: "development"
在我的dockerfile中,我已经定义了这个定义
ARG CURRENT_ENV
ENTRYPOINT /bin/sh -c "rm -f /app/tmp/pids/*.pid && [[ $CURRENT_ENV = 'dev' ]] && /usr/local/rbenv/versions/`cat .ruby-version`/gemsets/my-project/bin/foreman start -f Procfile || /usr/local/rbenv/versions/`cat .ruby-version`/gemsets/my-project/bin/foreman start -f Procfile.hot; tail -f /dev/null"
,但是当我使用“ docker-compose”启动容器时在“ ='dev'”部分之前,入口点似乎没有拾取变量……
myco-deploy-web-1 | /bin/sh: -c: line 0: `rm -f /app/tmp/pids/*.pid && [[ = 'dev' ]] && /usr/local/rbenv/versions/2.4.5/gemsets/my-project/bin/foreman start -f Procfile || /usr/local/rbenv/versions/2.4.5/gemsets/my-project/bin/foreman start -f Procfile.hot; tail -f /dev/null'
什么是将构建arg/env var传递给我的入口处命令的正确方法?
I want to pass an env/build var to my Dockerfile for use in its entryxoint and thought I could do it from the docker-compose file like so
web:
restart: "no"
build:
context: ../my-project
args:
CURRENT_ENV: "development"
In my Dockerfile, I have this defined
ARG CURRENT_ENV
ENTRYPOINT /bin/sh -c "rm -f /app/tmp/pids/*.pid && [[ $CURRENT_ENV = 'dev' ]] && /usr/local/rbenv/versions/`cat .ruby-version`/gemsets/my-project/bin/foreman start -f Procfile || /usr/local/rbenv/versions/`cat .ruby-version`/gemsets/my-project/bin/foreman start -f Procfile.hot; tail -f /dev/null"
However when I start my containers using “docker-compose up”, it doesn’t appear the entry point is picking up the variable as it has a empty string before the “= ‘dev’” section …
myco-deploy-web-1 | /bin/sh: -c: line 0: `rm -f /app/tmp/pids/*.pid && [[ = 'dev' ]] && /usr/local/rbenv/versions/2.4.5/gemsets/my-project/bin/foreman start -f Procfile || /usr/local/rbenv/versions/2.4.5/gemsets/my-project/bin/foreman start -f Procfile.hot; tail -f /dev/null'
What’s the proper way to pass the build arg/env var to my ENTRYPOINT command?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
入口点需要变量为环境变量,而不是构建arg。
你可以做到这一点
,它应该起作用
The ENTRYPOINT needs the variable to be an environment variable rather than a build arg.
You can do this
and it should work