Dockerfile, getting "failed to compute cache key" in the build

Hello all,
I am new to Docker and Github.
I have forked the famous repo of robot-shop into my own Github account:

After I have done it I have changed some files locally. Every time I have done docker-compose pull and docker-compose up I was getting the image from the main instana Github. Therefore, I have entered to the Dockerfile in order to change a folder that it will copy directly from my local folder.

This is the Dockerfile, what I have changed it is bold is only the last line, only one folder!

FROM alpine AS build

WORKDIR /instana

RUN apk add --update --no-cache curl


RUN if [ -n "$KEY" ]; then \
    sensor_version=$(curl --user "_:$KEY" ${ARTI_PATH} | grep -o '>[0-9]\+\.[0-9]\+\.[0-9]\+'| cut -f 2 -d '>'|sort -V|tail -1 ); \
    echo "Downloading sensor version ${sensor_version} for Nginx version 1.21.6" ; \
    curl \
    --output \
    --user "_:$KEY" \
    ${ARTI_PATH}/${sensor_version}/ && \
    unzip && \
    mv && \
    mv; \
    else echo "KEY not provided. Not adding tracing"; \
    touch; \

FROM nginx:1.21.6


    USER_HOST=user \
    CART_HOST=cart \
    SHIPPING_HOST=shipping \
    PAYMENT_HOST=payment \
    RATINGS_HOST=ratings \

# Instana tracing
COPY --from=build /instana/*.so /tmp/

COPY /root/
ENTRYPOINT ["/root/"]

COPY default.conf.template /etc/nginx/conf.d/default.conf.template
COPY /home/thesonics/robot-shop/web/static /usr/share/nginx/html

I have run a build without a catch in order to build it again correctly.
Sadly, I got the following error:

> [stage-1 5/5] COPY /home/thesonics/robot-shop/web/static /usr/share/nginx/html:
failed to compute cache key: "/home/thesonics/robot-shop/web/static" not found: not found
ERROR: Service 'web' failed to build : Build failed

Is there an option just to change part of the Dockerfile?
If not, how can I create one, I am very new at this tech.



Just to ask the obvious: does the file /home/thesonics/robot-shop/web/static exist on your local machine?


It is a folder and it is there:

thesonics@worker01:~/robot-shop$ cd web/static/
thesonics@worker01:~/robot-shop/web/static$ ls -l
total 56
-rw-rw-r-- 1 thesonics thesonics 1335 יונ 19 23:17 cart.html
drwxrwxr-x 2 thesonics thesonics 4096 יונ 19 23:17 css
-rw-rw-r-- 1 thesonics thesonics 77 יונ 19 23:17 empty.html
-rw-rw-r-- 1 thesonics thesonics 444 יונ 19 23:17 eum-tmpl.html
drwxrwxr-x 2 thesonics thesonics 4096 יונ 19 23:17 images
-rw-rw-r-- 1 thesonics thesonics 2588 יונ 20 14:25 index.html
drwxrwxr-x 2 thesonics thesonics 4096 יונ 19 23:17 js
-rw-rw-r-- 1 thesonics thesonics 2169 יונ 19 23:17 login.html
drwxrwxr-x 2 thesonics thesonics 4096 יונ 20 14:25 media
-rw-rw-r-- 1 thesonics thesonics 1328 יונ 19 23:17 payment.html
-rw-rw-r-- 1 thesonics thesonics 1371 יונ 19 23:17 product.html
-rw-rw-r-- 1 thesonics thesonics 559 יונ 19 23:17 search.html
-rw-rw-r-- 1 thesonics thesonics 843 יונ 19 23:17 shipping.html
-rw-rw-r-- 1 thesonics thesonics 1182 יונ 19 23:17 splash.html

Maybe I need to add another “/” in the end?

Dockerfile reference | Docker Documentation states:

COPY obeys the following rules:

  • The <src> path must be inside the context of the build (…)
  • (…)

See also How to include files outside of Docker's build context? - Stack Overflow.

I don’t fully understand it.
Do I need to do the following?
COPY /home/thesonics/robot-shop/web/static/index.hml /inusr/share/nginx/html

Can you please write me?


It is like @avbentem wrote: the files can not be outside the build context.

If your Dockerfile is located in /home/thesoncis/robot-shop/web, then modiy the COPY instruction to:

COPY static/index.hml /usr/share/nginx/html

The COPY and ADD instruction are not able use files outside your build context (which is usualy the folder where the Dockerfile is).

1 Like

Thank you!
It is more clear now, I will test it again.

I got an error on it as well

COPY static/index.hml /usr/share/nginx/html

Please share the complete web: block form your compose file.

Here it is:

      context: web
        # agent key to download tracing libs
    image: ${REPO}/rs-web:${TAG}
      - catalogue
      - user
      - shipping
      - payment
      - "8080:8080"
      - robot-shop
      test: [ "CMD", "curl", "-H", "X-INSTANA-SYNTHETIC: 1", "-f", "http://localhost:8080/" ]
      interval: 10s
      timeout: 10s
      retries: 3
    # Uncomment to enable Instana EUM
    # environment:
      # INSTANA_EUM_KEY: <your eum key>
      # INSTANA_EUM_REPORTING_URL: <your reporting url>
      <<: *logging


so the context relative to the Dockerfile is web, then the Dockerfile in this folder should use the relative path as first arguement of COPY. This is what you did, this is what should have worked…

No idea then. I am afraid this is for somone else to answer.

Thanks for your help!

There is one more thing that commes to mind. If things don’t make sense, usualy the snap version of docker is installed. Please use following command to check if it’s the case:

me@node:~$ snap list docker
error: no matching snaps installed

If you get a different output than I did, please remove the snap package and install the docker engine (!=Docker Desktop) package from docker’s own repositories (see: Install Docker Engine | Docker Documentation)!

What error exactly? @meyay may be right with suspecting snap, but “an error” is never enough information to help you. We are just sometimes lucky to figure it out. “An error” can be related to the COPY instruction but it can also be related to something else after the COPY. It is always a good practice to share error messages again even if you are sure that the message is the same so we can all focus on something else.

An other suggestion. When you are not sure what is in your actual build context, you can always copy copy everything and see what it will copy to the image:

COPY . /debug

If it works, you can run a container from the image and check the files in /debug

It is however not completely harmless, since if you don’t know what the context is, it can be your root directory (not likely, based on the docker compose file)

I was having the same issue and fixed it by removing the matching pattern in my .dockerignore file.