compose icon indicating copy to clipboard operation
compose copied to clipboard

add values to an existing environment variable during service starting

Open lmesz opened this issue 10 years ago • 4 comments

Sorry, maybe it is answered in another place, but I didn't find the solution. So my problem is the following. We use tomcat and we pass a lot of values to CATALINA_OPTS during image builds, but not all of them cause some of them determined when the container starts. I would like to extend the CATALINA_OPTS variable during service starting.

Here is an example image.

FROM alpine

ENV EXAMPLE_VARIABLE 42

ADD test_script.sh /

CMD ["/test_script.sh"]

The content of the test_script.sh is the following:

#!/bin/sh

echo $EXAMPLE_VARIABLE

The compose file is looks like this:

test:
    build: .
    environment:
        - EXAMPLE_VARIABLE=$$EXAMPLE_VARIABLE 56

So when I built the image and say docker-compose up.

Now i see: " $EXAMPLE_VARIABLE 56" in the output

Is it possible somehow to reach to see "42 56" in the console ?

lmesz avatar Feb 15 '16 10:02 lmesz

It is not possible to do this in the Compose file, it doesn't have access to the container environment (where 42 is set).

You would need to use an entrypoint script to join the environment variables (and use different variables for each).

dnephin avatar Feb 16 '16 17:02 dnephin

Hy thanks for the answer. At this time I can't do the same with docker itself. Don't you think it would be great if user could extend the env vars ?

lmesz avatar Feb 18 '16 08:02 lmesz

The current option of using different variables and joining them doesn't seem all that bad. I don't see how extending would work when you don't have the target environment available.

dnephin avatar Feb 18 '16 21:02 dnephin

Okay I understand it, but looks weird that when I would like to extend CATALINA_OPTS I have to write a script for this instead of CATALINA_OPTS="$CATALINA_OPTS -Djava.rmi.port=...."

lmesz avatar Feb 20 '16 12:02 lmesz