Home > Back-end >  Why is the dockerfile not able to COPY?
Why is the dockerfile not able to COPY?

Time:07-21

I'm creating simple React app with Docker image but for some reason I keep getting the following error:

COPY failed: file not found in build context or excluded by .dockerignore: stat build: file does not exist

Here's the dockerfile:

FROM /httpd:2.4.38

ENV SRVROOT=/usr/local/apache2

ENV myapp=$SRVROOT/myapp

COPY /app/build $myapp
COPY /Docker/run.sh $SRVROOT
COPY /Docker/httpd.conf $SRVROOT/conf/

RUN chmod 755 $SRVROOT/run.sh

CMD ["/usr/local/apache2/run.sh"]

CodePudding user response:

The first argument to COPY is the location of the file on the host machine. The leading slash means you’re trying to copy from /app and /Dockerfile (at the root of your computer), which is outside Docker context. Those files should be relative to the current directory:

COPY ./app/build $myapp
COPY ./Docker/run.sh $SRVROOT
COPY ./Docker/httpd.conf $SRVROOT/conf/

CodePudding user response:

The --from flag is used for multi-stage builds. It does not look like this is your case. Try removing the --from flag from your dockerfile

CodePudding user response:

Try using their relative path for the files you want to copy Thanks

  • Related