Heroku run Docker image with port parameter
The question is quite old now, but still I will write my answer here if it can be of some help to others.
I have spring-boot App along with swagger-ui Dockerized and deployed on Heroku.
This is my application.yml looks like:
server: port: ${PORT:8080} forward-headers-strategy: framework servlet: contextPath: /my-appspringdoc: swagger-ui: path: '/swagger-ui.html'
Below is my DockerFile configuration.
FROM maven:3.5-jdk-8 as maven_buildWORKDIR /appCOPY pom.xml .RUN mvn clean package -Dmaven.main.skip -Dmaven.test.skip && rm -r targetCOPY src ./srcRUN mvn package spring-boot:repackage########run stage########FROM openjdk:8-jdk-alpineWORKDIR /appRUN apk add --no-cache bashCOPY --from=maven_build /app/target/springapp-1.1.1.jar ./#run the app# 256m was necessary for me, as I am using free version so Heroku was giving me memory quota limit exception therefore, I restricted the limit to 256mENV JAVA_OPTS "-Xmx256m"ENTRYPOINT ["java","${JAVA_OPTS}", "-jar","-Dserver.port=${PORT}", "springapp-1.1.1.jar"]
The commands I used to create the heroku app:
heroku createheroku stack:set container
The commands I used to build image and deploy:
docker build -t app-image .heroku container:push webheroku container:release web
Finally make sure on Heroku Dashboard the dyno information looks like this:
web java \$\{JAVA_OPTS\} -jar -Dserver.port\=\$\{PORT\} springapp-1.1.1.jar
After all these steps, I was able to access the swagger-ui via
Your Docker container is required to listen to HTTP traffic in the port specified by Heroku.
Looking at the Dockerfile in the Github repo for swaggerapi/swagger-ui, it looks like it already supports the PORT environment variable: https://github.com/swagger-api/swagger-ui/blob/be72c292cae62bcaf743adc6236707962bc60bad/Dockerfile#L13
So maybe you don't really need to do anything?It looks like this image would just work, if shipped to Heroku as a web app.