During the Docker build phase I pass in an argument for the particular JAR file I want to copy into the container.
Docker Build
docker build -t foo-service . --build-arg FAT_JAR=foo-service-1.0.0-SNAPSHOT
Dockerfile
FROM maven:3.3-jdk-8-alpine
# Install packages
RUN apk add --no-cache curl tar bash wget
EXPOSE 9000
ARG FAT_JAR
RUN echo "Copying $FAT_JAR.jar to container"
# Copy Fat Jar to directory
RUN mkdir /home/test
COPY target/$FAT_JAR.jar /home/test/
ADD config /home/test/config
# Set Jar permissions
RUN chmod -R 766 /home/test
CMD cd /home/test && java -jar "$FAT_JAR.jar" server config/local.yml
When I try to run the Docker container it cannot open my jar file because $FAT_JAR
is not persisted inside the container.
Docker Run
docker run --add-host="localhost:10.0.2.2" -t foo-service
Error
Error: Unable to access jarfile .jar
How can I persist or make the Container know which file it needs to load?
i.e.
java -jar foo-service-1.0.0-SNAPSHOT.jar server config/local.yml
Thanks