Reputation: 7937
I am working with spring-boot along with docker images.
I am running my springboot
application directly from IntelliJ
name as runtime
with some of argument like below
-DCONFIG_DIR=D:\baseapimanager\runtime\config
I am able to run it successfully.
But by creating a docker image and running that image, it's not able to run. As i am not aware about how to pass argument while running docker image.
Here i had shared my Docker file contents as well.
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD target/docker-runtime.jar docker-runtime.jar
EXPOSE 8091
ENTRYPOINT ["java","-jar","docker-runtime.jar"]
And running below docker command i am trying to create image file for same.
docker build -f Dockerfile -t docker-runtime .
After this executing below command to run this generated image file.
docker run -p 8091:8091 docker-runtime
Without passing that argument and commenting business with that argument, it's working perfectly fine.
Any help will be appreciated.
Upvotes: 1
Views: 1624
Reputation: 7937
I had made below changes in my Docker file.
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD target/docker-runtime.jar docker-runtime.jar
EXPOSE 8091
ENTRYPOINT ["java","-jar","-DCONFIG_DIR=/shareddata","docker-runtime.jar"]
And while running an image i had bind that address using below command , and it's working fine.
docker run -p 8091:8091 --mount type=bind,source=/c/Users/lenovo/data,target=/shareddata docker-runtime
This had resolved my problem.
Upvotes: 0
Reputation: 2474
So to pass an argument into docker build do the following....
add the above line in the docker compose file.....
use the above in the dockerfile and access the variable
Upvotes: 0
Reputation: 36103
If CONFIG_DIR is a parameter you consume with Spring configuration @Value
or @ConfigurationProperties
you can pass the parameter as environment variable as well.
Environment variables can be passed to the container with -e
docker run -p 8091:8091 -e CONFIG_DIR=D:\baseapimanager\runtime\config docker-runtime
But as D:\baseapimanager\runtime\config looks like a Windows path that will not be visible inside the Docker container you have to add the configs to the docker image as well or mount a docker volume and the the parameter must point to the volume.
Upvotes: 2