When building a Docker image, there is a problem with the path to the ADD or COPY file.

  docker, question

InDockerfileUnder the current directory, when using the build command to build a mirror

docker build --rm -t image-name .

Exception occurred:

ADD failed: stat /var/lib/docker/tmp/docker-builder055888630/install/xxx.zip: no such file or directory

The directory structure is like this:

.
 ├── Dockerfile
 └── install
 └── xxx.zip

DockerfileThe content of the document is also relatively simple:

FROM openjdk:8u131-jre-alpine
 ADD install/xxx.zip /opt/
 ...

BeforewindowsThere is no problem in executing the ADD command in this way. now switch toUbantuOnly in the past have such problems been discovered. . .
In addition,Docker version 17.09.0-ce
I also checked it on the internet and found similar problems.
Say “add”.dockerignoreFile, Command Designation-fParameters. . .
All these have been tried, but they are useless. . .

Checked stackoverflow.
Move the answer, there are probably the following solutions

  1. If you want to add/copy, the file must be in the same root directory as the Dockerfile.

  2. Context can be set

    version: '3.3'
     services:
     yourservice:
     build:
     context: ./
     dockerfile: ./docker/yourservice/Dockerfile
  3. Mount file

Reference link