Stop Generating Multiple Docker Images After Code Updates
The Dockerfile is located in the project’s root directory, and I use the following command to build the Docker image:
./gradlew build # With JDK 17 installed docker build .
After a successful build of the Docker image from the source code, I use the following command to tag the Docker image:
docker tag cda504be51ab s-pdf:latest
after give tag I run the Docker image container with this command:
docker run -d -p 8200:8080 --name s-pdf s-pdf:latest
The Docker image is now operational on my server’s IP and port. However, I encounter the issue that whenever I make new changes to the source code, I have to rebuild the Docker image again using the Dockerfile located in the project root directory.
I manually delete the previously running container and image using the following command: docker rmi 2159208c0484
how can I make changes to the already built Docker image without having to create and build a new Docker image everytime, or how can I test the applied changes in the source code before building the Docker image?
Thank you.
can you probably do a volume mount on the jar file itself app.jar
to swap out the new jar once built
like this? docker run -d -p HOST_PORT:CONTAINER_PORT --name CONTAINER_NAME -v HOST_JAR_FILE_PATH:CONTAINER_JAR_FILE_PATH IMAGE_NAME:TAG
Where is the app.jar located in the Stirling PDF project directory?
docker run -d -p 8200:8080 --name s-pdf -v /path/to/your/app.jar:/app/app.jar s-pdf:latest
to swap out the new jar once built
It is not possible to implement the new changes without building.
to swap out the new jar once built
It is not possible to implement the new changes without building.
to swap out the new jar once built
I mean building the jar here not docker, you can keep the older docker image and add the newly built jar
As you show here docker run -d -p 8200:8080 --name s-pdf -v /path/to/your/app.jar:/app/app.jar s-pdf:latest
and path is just /app,jar at root
you can keep the older docker image and add the newly built jar
Yes I've keep the older docker image, please explain how to built newly jar?
After changes in source code I've to run again ./gradlew build & docker build .?
it's enough to run this ./gradlew build to built new jar? then i will mount into docker image.
please update.
The gradle build builds the new jar It's in the build/libs folder
That new jar you can add to docker with the volume mount
The gradle build builds the new jar It's in the build/libs folder
That new jar you can add to docker with the volume mount
Thank you so much for the update. yes, the gradle build the new jar file in build/libs folder.
after done changes in source code i've run this command ./gradlew build and next docker run -d -p 8200:8080 --name s-pdf -v /Users/ianasystems/Desktop/Stirling-PDF/build/libs/Stirling-PDF-0.22.8.jar:/app/app.jar s-pdf:latest
container start again but changes not apply.
Just app.jar Not app/app
If you check the docker filesystem you can find the location of the jar and it's named etc yourself
Thank you so much @Frooodle,
I've managed to mount the newly built JAR file, and the changes have been successfully applied.