2

Thanks for any help given!

I am new to Docker (Using 17.06.2-ee-10), and currently I am using it on Windows Server 2016, running windowsservercore image. My question is simple.

In my dockerfile I have

ARG destpath=C:\path\ ARG javafile=java.exe 

What I want to do is make another variable

ARG javapath=$destpath$javafile 

This is where I run into problems.

If I RUN echo %javapath% it returns $destpath$javafile (And sometimes not even that)

It never takes the added variables together. I have tried a few different things, such as making (ARG javapath=%destpath%%javafile%.) or trying to escape the "\" characters on the path. But nothing works.

I am a beginner and unsure if I need to be more detailed in my question, or dockerfile just doesn't allow what I am trying to do. If you need more clarification please let me know.

Thanks

Arthur

1 Answer 1

2

Putting curly braces around your variables, instead of just in potentially ambiguous cases, can be considered good programming practice. So, try the curly braces. This worked for me.

UPDATED ANSWER:

Sorry, I should have tested the values that YOU provided. Yeah, to make it work I had to wrap C:\path\ in single quotes:

FROM centos:latest ARG destpath='C:\path\' ARG javafile=java.exe ARG javapath=${destpath}${javafile} RUN echo $javapath 

Result:

$ docker build -t temp . Sending build context to Docker daemon 2.048kB Step 1/5 : FROM centos:latest ---> e934aafc2206 Step 2/5 : ARG destpath='C:\path\' ---> Running in 61f1aa0ea477 Removing intermediate container 61f1aa0ea477 ---> f49332bb07f9 Step 3/5 : ARG javafile=java.exe ---> Running in 7f965bea7edf Removing intermediate container 7f965bea7edf ---> b1d66e9b07ff Step 4/5 : ARG javapath=${destpath}${javafile} ---> Running in 9cfb4e2274f3 Removing intermediate container 9cfb4e2274f3 ---> 65dc408e384b Step 5/5 : RUN echo $javapath ---> Running in 7906c930caef C:\path\java.exe ##################################### there you go Removing intermediate container 7906c930caef ---> 887ef91def32 Successfully built 887ef91def32 Successfully tagged temp:latest 

OLD ANSWER:

FROM centos:latest ARG destpath=hello ARG javafile=world ARG javapath=${destpath}${javafile} RUN echo $javapath 

My result was as following:

$ docker build -t temp . Step 1/5 : FROM centos:latest ---> e934aafc2206 Step 2/5 : ARG destpath=hello ---> Running in 30f047122373 Removing intermediate container 30f047122373 ---> 582d3a801fd0 Step 3/5 : ARG javafile=world ---> Running in 78817656b729 Removing intermediate container 78817656b729 ---> a3afa410e42e Step 4/5 : ARG javapath=${destpath}${javafile} ---> Running in 8baf8c862572 Removing intermediate container 8baf8c862572 ---> 1a9c012e4d57 Step 5/5 : RUN echo $javapath ---> Running in 48ee08e6452d helloworld ############################################## there it is Removing intermediate container 48ee08e6452d ---> 9d72ba2aab67 Successfully built 9d72ba2aab67 Successfully tagged temp:latest 

P.S. If this doesn't work, it's windows' fault.

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

2 Comments

Thank you for your help. Unfortunately it doesn't work when I try it, my echo $javapath results on $javapath and echo %javapath% results in ${destpath}${javafile}. Seems to be a windows issue, and I have yet to see a solution/example online.
windows is not the best thing to use with... everything when you do programming...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.