add values to an existing environment variable during service starting
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 ?
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).
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 ?
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.
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=...."