Spring system parameter is being ignored

时间:2017-08-30 20:11:45

标签: spring docker environment docker-container

I created my Dockerfile where I want to create a simple Spring Boot Webapp listening on a port.

In [61]: a[:,-1] = 0

In [62]: a
Out[62]: 
array([[ 3, -3,  0],
       [ 2,  2,  0],
       [ 0, -3,  0],
       [ 0,  1,  0]])

In [63]: mask = a > 0

In [65]: np.where( mask.any(0), np.einsum('i...,i...->...',a,mask)/mask.sum(0), 0)
__main__:1: RuntimeWarning: invalid value encountered in true_divide
Out[65]: array([ 2.5,  1.5,  0. ])

My webapps application.properties defines the following:

masking

Starting my docker container via IntelliJ Docker Plugin I give it the parameter:

mask = a > 0 vm = mask.any(0) # valid mask out = np.zeros(a.shape[1]) out[vm] = np.einsum('ij,ij->j',a[:,vm],mask[:,vm])/mask.sum(0)[vm]

Running FROM java:8 VOLUME /tmp ENV port=123 #WORKDIR /workdir ADD /target/docker-test-0.1.jar dockertest.jar EXPOSE $port RUN bash -c 'touch /dockertest.jar' #ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom -Dserver.port=$port","-jar","/dockertest.jar"] ENTRYPOINT java -jar /dockertest.jar -Djava.security.egd=file:/dev/./urandom -Dserver.port=$port (bootapp is the containers name) gives me following information about the port environment variable and the entrypoint:

server.port=666

And Spring Boots log says this:

port=555

So the port defined in docker inspect bootapp was not overwritten by a runtime parameter.

This tells me that "Entrypoint" : [ "/bin/sh", "-c", "java -jar /dockertest.jar -Djava.security.egd=file:/dev/./urandom -Dserver.port=$port" ], "Env" : [ "port=555", ...], actually was able to be resolved but the variable in ENTRYPOINT wasn't.

I already changed ENTRYPOINT to shell form but that did not helped as you can see through my Dockerfile

1 个答案:

答案 0 :(得分:0)

系统变量位于java执行命令中的错误位置。 它必须放在Initializer选项之前。

<强>错误

PROFILES=$(awk -F"\\\]|\\\[" '/^\[/{print $2}' ~/.aws/credentials)

select PROFILE in $PROFILES; do
  export AWS_ACCESS_KEY_ID="$(aws configure get aws_access_key_id --profile $PROFILE)"
  export AWS_SECRET_ACCESS_KEY="$(aws configure get aws_secret_access_key --profile $PROFILE)"
  export AWS_DEFAULT_REGION="$(aws configure get region --profile $PROFILE)"
  break
done

echo AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
echo AWS_SECRET_ACCESS_KEY=$(echo $AWS_SECRET_ACCESS_KEY|tr '[:print:]' '*')
echo AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION

从右

-jar