I'm deploying an Docker image with CMD line in it :
CMD ["java","-XX:+UnlockExperimentalVMOptions","-XX:+UseCGroupMemoryLimitForHeap","-Djava.security.egd=file:/dev/./urandom","-Dspring.server.port=$PORT","-Dserver.port=$PORT","-jar","/life-project.jar"]
while in the log it looks like :
2018-08-06T10:51:17.489612+00:00 heroku[web.1]: Starting process with command java -XX:\+UnlockExperimentalVMOptions -XX:\+UseCGroupMemoryLimitForHeap -Djava.security.egd\=file:/dev/./urandom -Dspring.server.port\=\48227 -Dserver.port\=\48227 -jar /life-project.jar
with the following error :
2018-08-06T10:51:26.106011+00:00 app[web.1]: ***************************
2018-08-06T10:51:26.106012+00:00 app[web.1]: APPLICATION FAILED TO START
2018-08-06T10:51:26.106014+00:00 app[web.1]: ***************************
2018-08-06T10:51:26.106015+00:00 app[web.1]:
2018-08-06T10:51:26.106017+00:00 app[web.1]: Description:
2018-08-06T10:51:26.106018+00:00 app[web.1]:
2018-08-06T10:51:26.106020+00:00 app[web.1]: Failed to bind properties under 'server.port' to java.lang.Integer:
2018-08-06T10:51:26.106021+00:00 app[web.1]:
2018-08-06T10:51:26.106022+00:00 app[web.1]: Property: server.port
2018-08-06T10:51:26.106024+00:00 app[web.1]: Value: $PORT
2018-08-06T10:51:26.106025+00:00 app[web.1]: Origin: "server.port" from property source "systemProperties"
2018-08-06T10:51:26.106026+00:00 app[web.1]: Reason: failed to convert java.lang.String to java.lang.Integer
2018-08-06T10:51:26.106028+00:00 app[web.1]:
2018-08-06T10:51:26.106029+00:00 app[web.1]: Action:
2018-08-06T10:51:26.106030+00:00 app[web.1]:
2018-08-06T10:51:26.106032+00:00 app[web.1]: Update your application's configuration
What should I change in the configuration?
You'll need to create the following entry in your application.properties
(or yaml):
server.port=${PORT:8080}
The reason is described in the Docker docs . You can put $
vars in the CMD
.
The other answers are correct generally speaking, but depending on the environment, (1) it's possible PORT
is not defined, and (2) it's possible for the var PORT
to get lost somewhere in the translation between host > container > JVM. This is especially the case if you use -Dserver.port
instead of --server.port
.
For me, what solved this was to default the value in both application.properties and Dockerfile, and to use --server.port
instead of -Dserver.port
:
// application.properties
server.port=${PORT:8080}
// Dockerfile
CMD ["java", "-jar", "myapp.jar", "--server.port=${PORT:8080}"]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.