1

I'm trying to use args in a docker compose file.

The docker-compose file:

version: '3'

services:
  service1:
    image: test
    restart: always
    build:
      context: C:/ProgramData/
      dockerfile: Dockerfile
      args:
        entry: 1
    volumes:
      - C:/ProgramData/test 

The Dockerfile:

FROM microsoft/dotnet-framework:3.5
ARG entry
WORKDIR C:\\test
ADD ["/bin/x86/Release/","C:/test/"] 
ENTRYPOINT ["C:\\test\\file.exe",  ${entry}]

I don't know how exactly works the syntax in the docker file. How I have to put the arg in the ENTRYPOINT?

JosepB
  • 2,205
  • 4
  • 20
  • 40
  • It seems to me that you are using it right. Try adding `RUN echo ${entry}` between the `ADD` and `ENTRYPOINT` directives to see whether it is being passed OK (temporarily for debufg purposes). In case it is, I would focus on what does `file.exe` do with a parameter provided like this. Isn't there a possibility it already works OK? Perhaps try to wrap the variable it into double-quotes.. – helvete Jun 26 '18 at 11:29
  • Sorry @helvete, I forgot to say that I'm using docker for Windows. In this environment is like `RUN echo %entry%` for debug. The arguments have the correct value. Now I'm focusing on the `ENTRYPOINT`. I'm trying to pass the `ARG` to an `ENV` as @jannis says. But it doesn't work – JosepB Jun 27 '18 at 05:51

2 Answers2

1

You cannot use ARG in ENTRYPOINT (at least not directly). See How to pass ARG value to ENTRYPOINT?:

Both ARG and ENV are not expanded in ENTRYPOINT or CMD. (https://docs.docker.com/engine/reference/builder/#environment-replacement) However, because ENVs are passed in as part of the environment, they are available at run time, so the shell can expand them. (This means you can't use the array form of ENTRYPOINT or CMD.)

jannis
  • 4,843
  • 1
  • 23
  • 53
1

I solved this issue by changing the Dockerfile as follows:

FROM microsoft/dotnet-framework:3.5

ARG ENTRY
ENV my_env=$ENTRY

#RUN echo %ENTRY%
#RUN echo %my_env%

WORKDIR C:\\test
ADD ["/bin/x86/Release/","C:/test/"]

ENTRYPOINT C:/test/file.exe %my_env%
JosepB
  • 2,205
  • 4
  • 20
  • 40