Home > Net >  docker failed to compute cache key: /path not found: not found
docker failed to compute cache key: /path not found: not found

Time:10-12

I just started with the docker and I am creating docker image from my code. Here is the dir structure

project
  /deployment
     /Dockerfile.project1
  /services
     /ui
        /project1

and Here is the code in Dockerfile.project1

FROM node:14

# arguments
ARG BUILD_COMMIT
ARG BUILD_BRANCH
ARG BUILD_TAG
# port number for app
ARG PORT=3000
ARG APP=adam_website_ui

LABEL build.tag=${BUILD_TAG}
LABEL app=${APP}

# set the env
ENV BUILD_BRANCH=${BUILD_BRANCH}
ENV BUILD_COMMIT=${BUILD_COMMIT}


WORKDIR /app

# Assiging user
USER root
RUN echo "$(date ' %Y-%m-%d %H:%M:%S'): ======> Setup Appusr" \
    && groupadd -g 1001 appusr \
    && useradd -r -u 1001 -g appusr appusr \
    && mkdir /home/appusr/ \
    && chown -R appusr:appusr /home/appusr/\
    && chown -R appusr:appusr /app

# copy the relavant code
COPY ../services/ui/project1 /app/

# installing deps
RUN npm install 
RUN npm run build
RUN SET PORT=${PORT} && npm start

USER appusr:appusr

but this is showing

 => ERROR [4/7] COPY ../services/ui/project1 /app/                                                                         0.0s 
------
 > [4/7] COPY ../services/ui/project1 /app/:
------
failed to compute cache key: "/services/ui/project1" not found: not found

and I am building using this command from deployment folder

docker build -t website_ui -f Dockerfile.project1 .

what can be the issue?

CodePudding user response:

If you run docker build within the directory project/deployment with build context ., then docker is not able to find the files in project/services.

Try to run docker build -t website_ui -f deployment/Dockerfile.project1 . (the last argument is the build context)

From the docs:

The docker build command builds Docker images from a Dockerfile and a "context". A build's context is the set of files located in the specified PATH or URL.

CodePudding user response:

When you build a Docker image you must specify a path to a directory which will be the build context, this is the dot at the end of your docker build command. The content of this directory will then be copied by Docker (probably into an internal Docker directory), which is why you can't COPY paths outside the context.

You should see a message like "Uploading context of X bytes" when running docker build.

Change your COPY instruction to COPY services/ui/project1 /app/ and build your image from the project's root directory:

docker build -t website_ui -f deployment/Dockerfile.project1 .

Read more about the build context on the docker build documentation

  • Related