1

I have a docker-compose and a docker file.

In the docker file, I have COPY instructions where I specify

The problem is, I have a new JAR file in the same folder as my dockerfile but it keeps copying the older jar. I have no idea of where it is getting the older jar. I have made sure to have only one jar.

COPY ./xxxx.jar /home/dev/xxxxd.jar

Nesan Mano
  • 1,586
  • 2
  • 13
  • 33
  • can you build the image with no cache docker-compose build --no-cache – Gonzales Gokhan Dec 17 '20 at 21:49
  • I don't use any build instructions – Nesan Mano Dec 17 '20 at 22:02
  • When you have a new jar file you will have to build a new docker image right ? am i missing something here ? either by using docker or docker-compose. you need to build a new image – Gonzales Gokhan Dec 17 '20 at 22:08
  • Exactly, I have found the culprit. the images were not rebuilt but rather taken from a previous build. I don't if we could force the images to be rebuild or delete the images when the containers are deleted – Nesan Mano Dec 17 '20 at 22:43

1 Answers1

0

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

earlonrails
  • 4,736
  • 3
  • 29
  • 47