skip to Main Content

This is my docker file (excluding prod part) :

FROM node:16 as development

WORKDIR /usr/src/app

RUN  apt-get update 
  && apt-get install -y wget 
  && rm -rf /var/lib/apt/lists/*


RUN wget "https://cdn.sstatic.net/Img/unified/sprites.svg" -O sprites.svg
# ERROR COPY ./sprites.svg ./
COPY sprites.svg ./

# it Works
COPY package*.json ./

RUN npm install --only=development

COPY . .

RUN npm run build

When i run docker build, i have this error:

 => CACHED [development 2/9] WORKDIR /usr/src/app                                                                                                  0.0s 
 => CACHED [development 3/9] RUN  apt-get update   && apt-get install -y wget   && rm -rf /var/lib/apt/lists/*                                     0.0s 
 => CACHED [development 4/9] RUN wget "https://cdn.sstatic.net/Img/unified/sprites.svg" -O sprites.svg                                             0.0s 
 => ERROR [development 5/9] COPY sprites.svg ./                                                                                                    0.0s 
 => CACHED [production 2/6] WORKDIR /usr/src/app                                                                                                   0.0s 
 => CACHED [production 3/6] COPY package*.json ./                                                                                                  0.0s 
 => CACHED [production 4/6] RUN npm install --only=production                                                                                      0.0s 
 => CANCELED [production 5/6] COPY . .                                                                                                             0.0s 
------
 > [development 5/9] COPY sprites.svg ./:
------
failed to compute cache key: "/sprites.svg" not found: not found

What can i do to fix this error? I need to put extarnal file in build docker image

3

Answers


  1. Chosen as BEST ANSWER

    I used wrong command COPY , as i understood COPY copies files from my local system to image ... and RUN wget downloaded file inside image to WORKDIR directory. I don't need COPY! ))


  2. Try this!

    RUN mkdir /code
    WORKDIR /code
    COPY file /code/
    

    I think it gives you an error because of this: COPY . .

    The syntax seems pretty wrong to me. You basically tell Docker to copy everything in.. everything

    Login or Signup to reply.
  3. In your case sprites.svg is not found on your given path.

    Check where you download the file with wget.

    You can use add or copy.

    Try ADD instead of wget for the external url

    The ADD command is used to copy files/directories into a Docker image. It can copy data in three ways:

    Copy files from the local storage to a destination in the Docker image.

    Copy a tarball from the local storage and extract it automatically inside a destination in the Docker image.

    Copy files from a URL to a destination inside the Docker image.

    ADD source destination
    

    Unlike its closely related ADD command, COPY only has only one assigned function. Its role is to duplicate files/directories in a specified location in their existing format. This means that it doesn’t deal with extracting a compressed file, but rather copies it as-is.

    COPY source destination
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search