I need to set an environment variable CLASSPATH
. In that variable I need to set the result of a command:
hadoop classpath --glob
This will return a ton of java libraries and they all need to get set into that CLASSPATH
variable. The big problem is that I can only run this command after the docker build is complete, meaning I have to do it in the ENTRYPOINT
. But I just cant get it working. I tried differen approaches:
ENTRYPOINT ["sh", "-c", "export CLASSPATH=$(hadoop classpath --glob) ...."
ENTRYPOINT ["sh", "-c", "set CLASSPATH=$(hadoop classpath --glob) ...."
ENTRYPOINT ["sh", "-c", "CLASSPATH=$(hadoop classpath --glob) ...."
ENTRYPOINT ["sh", "-c", "/bin/bash && export CLASSPATH=$(hadoop classpath --glob) ...."
But nothing of it is working. The command itself is working, I tested it using:
ENTRYPOINT ["sh", "-c", "echo $(hadoop classpath --glob) >> /tmp/classpath.tmp ...."
This file contains the correct content after startup. So there is just a problem with setting and persisting the environment variable. How am I supposed to set the environment variable? Usually you use something like
ENV CLASSPATH="some classpath"
But here I cant use the ENV
statement since it wont process the command $(hadoop classpath --glob)
In this case I would prefer to use a bash profile change the
SHELL
tosh -lc
instead ofsh -c
Dockerfile
Output of build
As you can see changing the SHELL from
sh -c
tosh -lc
starts loading our profile. So you will update the.profile
to exportCLASSPATH
based onRunning the container
Edit-1
Try this without the need of a profile
The only working solution for that problem was to not use an
ENTRYPOINT
in theDockerfile
at all./
Attention: you need to execute it by
. /entrypoint.sh
. Otherwise it wont work.