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:
services:
master:
container_name: master
env_file:
- variables.env
build:
context: ./subdirectory1/
dockerfile: Dockerfile
args:
My structure folders :
docker-compose.yml
subdirectory1/
DockerFile
subdirectory1/
DockerFile
master/
subdirectory2
DockerFile
subdirectory2
DockerFile
So in your DockerFile, add the following :
RUN mkdir -p /var
WORKDIR /var
WORKDIR /var
To copy the whole directory :
COPY ./master .
COPY ./master .
To copy subdirectories :
COPY ./master/ .
COPY ./master/ .
Docker version 20.10.8, build 3967b7d