admin管理员组

文章数量:1305974

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

本文标签: Read dockercompose environment mappings in entrypointshStack Overflow