1

I have very a simple docker file:

FROM tomcat:7.0
RUN echo $HOST_IP > /opt/serverIP

When I run my image (my-server) with follow command the file /opt/serverIP exists and it is empty:

docker run -e HOST_IP='172.16.1.1' -t my-server cat /opt/serverIP

How to write my environment value into a temporary file?


My docker version: Docker version 1.12.1, build 23cf638
This is my machine info:

Kernel Version: 4.4.0-36-generic
Operating System: Ubuntu 16.04 LTS
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.703 GiB
0

1 Answer 1

3

I believe you're confusing build-time variables with run-time variables. The "RUN" command is essentially executed at build time. Your "HOST_IP" value is supplied at run time.

The "CMD" instruction, however, is executed at run time. To approximately do what you're trying to do, define a "CMD" that writes $HOST_IP to the file. use "docker run" to run the image, and then use "docker exec" to verify the contents of the file.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, i change my docker file and my image is running. But the file not exists!
You'd have to update your post with exactly what you have now. It might also help to see the "docker build" output.
I risolve it using an sh script. Thanks and King regards

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.