0
ENV ADDRESS=http://peer1:8761/eureka/,http://peer2:8762/eureka/
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom", "-jar","/app.jar", "--eureka.client.serviceUrl.defaultZone=$ADDRESS"]

I want to specify the eureka address to the entrypoint via environment variables.But it still $ADDRESS when i use docker run,and i use ENTRYPOINT java -jar xxxx,it can be replaced correctly,but when i use ENTRYPOINT like ENTRYPOINT java -jar xxx.jar,and i use docker run image_name --spring.profiles.active=peer1,ending parameters active=peer1 will not take effect,What should I do to use environment variables and parameters in Entrypoint

talex
  • 17,973
  • 3
  • 29
  • 66
Calm
  • 119
  • 1
  • 10
  • Do you understand how ENTRYPOINT and CMD interact, and the exact difference between `ENTRYPOINT java ...` and `ENTRYPOINT ["java", ...]`? – David Maze Dec 04 '18 at 02:46
  • In my understanding,ENTRYPOINT java ... will explain by shell,so env variables will be explain,and i want use ENTRYPOINT["/bin/sh", "-c", "java", ...] can solve also pass env and cmd parameters,but it made a mistake – Calm Dec 04 '18 at 02:52
  • I think this might be a duplicate of https://stackoverflow.com/questions/37904682/how-do-i-use-docker-environment-variable-in-entrypoint-array – cdrini Dec 04 '18 at 04:23
  • i know use the entrypoint shell format will explain the env paramters,but cmd parameters will not append to entrypoint by this way – Calm Dec 04 '18 at 04:39
  • I want to know how to use env and the parameters end of docker run at the same time. – Calm Dec 04 '18 at 05:48

1 Answers1

0

I just tried resolving PATH in dockerfile and it worked for one scenario (I used CMD though) not sure if that helps. If this did not work let me know with more details.

There are two forms to specify command (Exec form and Shell form), and two ways to specify the default command(ENTRYPOINT and CMD) in a dockerfile.

Exec form:

FROM ubuntu
MAINTAINER xyz<xyz.gmail.com>
ENTRYPOINT ["ping"]

The command specified (ping) will run as PID 1. That is the reason why if we press CTRL + C (SIGTERM) is passed to PID1 process and container is shutdown.

Shell form:

FROM ubuntu
MAINTAINER xyz<xyz.gmail.com>
CMD echo $PATH

PATH got resolved to the shell environment PATH when run.(output verified).

shell form specifiies command tokens separated by spaces. shell form executes command by calling /bin/sh -c (this means PID 1 is actually the shell and the command specified in docker file is just another process)(pressing CTRL + C will not kill container)

Advantage of using shell form is since you are executing with /bin/sh -c we can resolve environment variables in command (in above example we are using PATH).

Hope this helps

Sergio
  • 3,317
  • 5
  • 32
  • 51
Sudhakar MNSR
  • 594
  • 1
  • 3
  • 17
  • Thank you for your answer,but how should i do let entrypoint can resolved the env parameter and the cmd parameters – Calm Dec 04 '18 at 04:45
  • I want to know how to use env and the parameters end of docker run at the same time. – Calm Dec 04 '18 at 05:48
  • I did not understand completely but I felt worth try..? Are you saying in Exec form you could see all ENV but not shell environment and in Shell form you are not seeing ENV but only shell environment (confirm my understanding of problem)? Just try ["sh", "-c", "java .....your command"] in Entrypoint. – Sudhakar MNSR Dec 04 '18 at 07:11
  • thanks, i have solved thisp probelm,i want use environment variable and use dynamic parameters in entrypoint – Calm Dec 14 '18 at 07:55
  • @Calm If possible share your findings and solution to the issue, with example. That may help others. – Sudhakar MNSR Dec 14 '18 at 08:33