Reputation: 926
I am trying to pass a variable simply from docker build file to docker file, however the variable is never resolved
version: '3'
services:
movie-discovery-server:
container_name: movie-discovery-server
build:
args:
PORT: 8761
context: /Users/admin/Downloads/movie-discovery-server
dockerfile: Dockerfile
image: movie-discovery-server:latest
environment:
- PORT=8761
expose:
- 8761
And here is the Dockerfile
FROM openjdk:8
ADD ./target/movie-discovery-server-0.0.1-SNAPSHOT.jar movie-discovery-server-0.0.1-SNAPSHOT.jar
ARG PORT
ENTRYPOINT ["java", "-jar", "movie-discovery-server-0.0.1-SNAPSHOT.jar", "--server.port=$PORT"]
however the $PORT is never resolved
---EDIT--- It turned out that I have made couple of mistakes in my files, I my answer below will contain the right file format
Upvotes: 0
Views: 240
Reputation: 926
It turned out that I was doing couple of things in the wrong way. For the docker compose file I introduced the following changes:
args
tag as it had no effectReplace the expose
tag with ports
tag, as the mapping was not working correctly
version: '3'
services:
movie-discovery-server:
container_name: movie-discovery-server
build:
context: /Users/admin/Downloads/movie-discovery-server
dockerfile: Dockerfile
image: movie-discovery-server:latest
ports:
- "8761:8761"
environment:
- PORT=8761
For the DockerFile, I have applied the advice I had from @codestation and let go with the JSON format
FROM openjdk:8
ADD ./target/movie-discovery-server-0.0.1-SNAPSHOT.jar movie-discovery-server-0.0.1-SNAPSHOT.jar
ARG PORT
ENTRYPOINT java -jar movie-discovery-server-0.0.1-SNAPSHOT.jar --server.port=$PORT
Upvotes: 0
Reputation: 3498
Neither ENTRYPOINT
nor CMD
will resolve variables when json array format is used.
If you need to resolve the PORT either use an entrypoint script or use the shell form notation for ENTRYPOINT
ENTRYPOINT java -jar movie-discovery-server-0.0.1-SNAPSHOT.jar --server.port=$PORT
Upvotes: 2