Pages

Saturday, November 6, 2021

Docker : COPY failed: file not found in build context or excluded by .dockerignore



I wanted copy /root/master directory in /var/  like this : cp -R /root/master /var/

However, I had the following error : COPY failed: file not found in build context or excluded by .dockerignore

I found the solution on Stackoverflow :

The <src> path must be inside the context of the build; you cannot COPY ../something /something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.

In fact, I needed to copy the master directory in a Docker sub folder because I used a docker-compose.yml with services:

version: "3"
services:
  master:
    container_name: master
    env_file:
      - variables.env
    build:
        context: ./subdirectory1/
        dockerfile: Dockerfile
        args:

 My structure folders :

docker-compose.yml 
subdirectory1/
DockerFile
        master/
subdirectory2
DockerFile


So in your DockerFile, add the following :

RUN mkdir -p /var
WORKDIR /var

To copy the whole directory :
COPY ./master .

To copy subdirectories :
COPY ./master/ .

Docker version 20.10.8, build 3967b7d

No comments:

Post a Comment

Débutez en crypto-monnaie de manière ludique avec les projets "Move to earn"

Les projets "Move to earn" sont des projets très en vogue en ce moment dans le monde de la crypto-monnaie. Le principe est simple ...