¿Cómo uso la variable de entorno Docker en el array ENTRYPOINT?


Si establezco una variable de entorno, digamos ENV ADDRESSEE=world, y quiero usarla en el script de punto de entrada concatenado en una cadena fija como:

ENTRYPOINT ["./greeting", "--message", "Hello, world!"]

Siendo world el valor del entorno variable, ¿cómo lo hago? Traté de usar "Hello, $ADDRESSEE" pero eso no parece funcionar, ya que toma el $ADDRESSEE literalmente.

Author: Psycho Punch, 2016-06-19

2 answers

Estás usando el exec form de ENTRYPOINT. A diferencia del shell form , el exec form no invoca un shell de comandos. Esto significa que el procesamiento normal de shell no ocurre. Por ejemplo, ENTRYPOINT [ "echo", "$HOME" ] no hará sustitución de variables en HOME HOME. Si quieres procesar el shell entonces usa el formulario shell o ejecuta un shell directamente, por ejemplo: ENTRYPOINT [ "sh", "-c", "echo $HOME" ].
Al usar el formulario exec y ejecutar un shell directamente, como en el caso del formulario shell, es el shell que está haciendo la expansión de la variable de entorno, no docker.(de Dockerfile reference)

En su caso, usaría shell form

ENTRYPOINT ./greeting --message "Hello, $ADDRESSEE\!"
 82
Author: vitr,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-02-23 16:04:38

Traté de resolver con la respuesta sugerida y todavía me encontré con algunos problemas...

Esta fue una solución a mi problema:

ARG APP_EXE="AppName.exe"
ENV _EXE=${APP_EXE}

# Build a shell script because the ENTRYPOINT command doesn't like using ENV
RUN echo "#!/bin/bash \n mono ${_EXE}" > ./entrypoint.sh
RUN chmod +x ./entrypoint.sh

# Run the generated shell script.
ENTRYPOINT ["./entrypoint.sh"]

Específicamente dirigidas a su problema:
RUN echo "#!/bin/bash \n ./greeting --message ${ADDRESSEE}" > ./entrypoint.sh
RUN chmod +x ./entrypoint.sh
ENTRYPOINT ["./entrypoint.sh"]

 0
Author: Ben Kauffman,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-04-18 17:20:14