0

I am using docker-compose to build the docker. The docker file is trying to copy the folder outside of the context as shown below

enter image description here

I have a docker folder inside that folder I have a docker file and docker-compose file. The content of the docker file is shown below

FROM openjdk:17

RUN set -x \
    mkdir -p fetebird-product

WORKDIR /fetebird-product
# Copy the source jar file to the docker destination folder
COPY ../../build/libs/*.jar /fetebird-product/

ENTRYPOINT ["java", "-jar", "/fetebird-product-api-0.1.jar"]

Docker compose

version: "3.9"
services:
  fetebird-product:
    build:
      context: .
      dockerfile: openjdk.dockerfile
    ports:
      - "8081:8081"
    depends_on:
      - mongodb
  mongodb:
    image: mongo:5.0.5
    ports:
      - "27017:27017"

While running the command docker compose up, getting the exception as

 => ERROR [4/4] COPY ../../build/libs/*.jar /fetebird-product/                                                                                                                                             0.0s
------
 > [4/4] COPY ../../build/libs/*.jar /fetebird-product/:
------
failed to solve: lstat /var/lib/docker/tmp/buildkit-mount850007301/build/libs: no such file or directory

I know this is the issue of path location, when I move the files outside the docker folder the COPY command words.

Just not sure how to point to the correct location outside of the context.

San Jaisy
  • 15,327
  • 34
  • 171
  • 290
  • "*Just not sure how to point to the correct location outside of the context.*" - We can not. – Turing85 May 08 '22 at 09:43
  • @Turing85 If I have a multiple docker file, putting the docker file in the root directory is not a good practice. Isn't it ?? – San Jaisy May 08 '22 at 09:53
  • We don't need to. When we call `docker build ...`, we can set the context directory and the path to the dockerfile manually. This means we can call `docker build ...` from one directory, set the context to another directory and use a containerfile located in a third directory. – Turing85 May 08 '22 at 09:59
  • @Turing85 what will be the solution for this COPY ../../build/libs/*.jar /fetebird-product/?? – San Jaisy May 08 '22 at 10:07
  • The paths referencing host files are always relative to the context directory. So if we set the context directory to whatever `directoryWhereDockerfileLives/../../` is, `../../build/libs/*.jar` becomes `build/libs/*.jar`. – Turing85 May 08 '22 at 10:14
  • @Turing85 I am sorry, but I didn't understand. Can you please show me an example with my docker-compose file – San Jaisy May 08 '22 at 10:19
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/244589/discussion-between-turing85-and-san-jaisy). – Turing85 May 08 '22 at 10:21

0 Answers0