So let's say your Dockerfile
looks like this:
FROM openjdk:8
COPY ./xxxx.jar /home/dev/xxxxd.jar
CMD ["java", "-jar", "/home/dev/xxxxd.jar"]
You have some folder for your project like
project/
Dockerfile
docker-compose.yml
xxxx.jar
old-xxxx.jar
You can make your docker-compose.yml
look like this:
version: "3.4"
services:
project:
build: .
volumes:
- ./:/home/dev
This line will copy the jar to the image at build time
COPY ./xxxx.jar /home/dev/xxxxd.jar
This docker-compose volume part is going to run docker container similar to using the following docker run command.
docker run -v ./:/home/dev project
This will mount your project folder to the /home/dev
before running.
Which should have your most recent jar which is the same jar as in your project folder.
If you are noticing something unusual you can try what I do when things go wrong.
docker-compose up --build
and if all else fails:
docker-compose stop && docker-compose rm -sfv && docker-compose up
Similar issues:
How do I mount a host directory as a volume in docker compose
Auto remove container with docker-compose.yml