最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Read docker-compose environment mappings in entrypoint.sh - Stack Overflow

programmeradmin0浏览0评论

I'm looking for some help with dockerfile and entrypoint. I am trying to dockerize an app and write environment variables from my docker compose like

services:
  test_container:
    image: container:main
    environment:
      - MY_VAR = 123

into a file at container creation time. This example is using one for simplicity, but there are about 30 variables that I need to be able to apply this solution to. I need to be able to reset variable at container start time, not have their values hard coded into the built image. My dockerfile invocation of entrypoint looks like

ENTRYPOINT ["/bin/sh", "/usr/local/bin/entrypoint.sh"]

and my entrypoint command to write into a file is

echo MY_VAR = $MY_VAR
echo MY_VAR = $MY_VAR \ >> info.txt

My entrypoint has been successfully writing vars to the file with this command if I define them in dockerfile like ENV MY_VAR=123 but I cannot figure out how to get an environment variable from my docker-compose to override this and be written to the text file in the entrypoint script. Do I need to define it as an ARG or ENV in the dockerfile too? Is there something wrong with how I'm invoking entrypoint? I ran docker container inspect and my env DOES include the MY_VAR that I'm setting in docker-compose - so I'm thinking there's something wrong with my entrypoint. I'm not sure if the way I'm going is the right way or if there's another route that work be better

发布评论

评论列表(0)

  1. 暂无评论