Home > OS >  Cannot copy from docker image using "COPY --from" command in Dockerfile
Cannot copy from docker image using "COPY --from" command in Dockerfile

Time:10-26

There is a directory inside the stain/jena-fuseki:4.0.0 image that cannot be copied while other directories can be. I have the following Dockerfile

FROM python:3.8.15-slim
COPY --from=stain/jena-fuseki:4.0.0 /fuseki /fuseki

If I run docker image build . I get the following response

Sending build context to Docker daemon  435.9MB
Step 1/2 : FROM python:3.8.15-slim
 ---> f0fe0cb74bac
Step 2/2 : COPY --from=stain/jena-fuseki:4.0.0 /fuseki /fuseki
COPY failed: stat fuseki: file does not exist

However, I looked into the image with docker run -it stain/jena-fuseki:4.0.0 and the directory does exist at the root level along with other directories which are copyable. E.g. following Dockerfile builds perfectly without any errors.

FROM python:3.8.15-slim
COPY --from=stain/jena-fuseki:4.0.0 /jena-fuseki /jena-fuseki

I have tried many things like changing the working directory with WORKDIR / and also things like COPY --from=stain/jena-fuseki:4.0.0 /fuseki/. /fuseki. However, none of them are working. I have also not excluded anything with .dockerignore

CodePudding user response:

You need to use a multi-stage build, see here: enter image description here

  • Related