Dockerfile is unable to find and copy local file when building image

163 Views Asked by At

I am helping my team to migrate our tomcat based application which runs on Java 8. The application is using docker-compose-up which is using a docker-compose.yaml file to build several dependencies inside the project, a high level structure of this docker-compose.yaml file:

version: "3.7"
services:

  # Local database setup using MySQL x.x.x
  db-app:
    build: ./appRoot/database
    hostname: "somehostname"
    environment:
      someEnvVar1:   x
      someEnvVar2:   y 
    ports:
      - "port1:port2"
    command: <some data initiation script run>

  # service setup block
  # run the awesome service inside a docker container
  service-app:
    build: ./appRoot/serviceName
    hostname: 'someHost'
    volumes:
      - $HOME/.aws/credentials:/home/tomcat/.aws/credentials
      - ./appRoot/serviceName/someSandBoxConfig/someFILE.jks:/someFILE.jks:Z
      - ./appRoot/serviceName/datadog:/datadog:rw
    ports:
      - "someport1:someport1"
      - "someport2:someport2"
    depends_on:
      - mock-app
      - db-app
    environment:
      FLAVOR: "someFlavor"
      CATALINA_OPTS: "-Duser.timezone=UTC -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9000"

< other dependency app .....>

Now inside each dependency app directory, there is separate Dockerfile written just for that dep app only.
So for the service-app above, I have Dockerfile under the dir ./appRoot/serviceName/Dockerfile

What I am trying to do: I created a new source text file called test.txt file sitting along side with the Dockerfile, and I want to be able to copy this file into the docker container from the source code when building it.

I have already tried the following code :

RUN mkdir /newDir
COPY test.txt /newDir
RUN ls -lah /newDir

when running dockerComposeUp command , I keep getting the error below:

#12 [ 7/19] COPY ./test.txt /newDir
#12 sha256:a3641aad21a23a5779d756b3fea8187ef76b7bca991c34b180b826e82ab66e58
#12 ERROR: "/test.txt" not found: not found
------
 > [ 7/19] COPY ./test.txt /newDir:
------
failed to compute cache key: "/test.txt" not found: not found

What am I missing here ?

1

There are 1 best solutions below

0
On

Alright, after hours of debugging, I finally fixed the issue, it turns out to be that we are defining the rules for copying files in the gradle.properties file where we have a docker block like this one:

docker {
    name "awesome-service"
    copySpec.into("/")
            .from ("./awesome-service") {
                include "someconfig/**"
    ....
    }

adding the dir I created then it works like a charm.......