Docker: adding a file from a parent directory
You can build the Dockerfile from the parent directory:
docker build -t <some tag> -f <dir/dir/Dockerfile> .
With docker-compose, you could set context folder:
#docker-compose.yml
version: '3.3'
services:
yourservice:
build:
context: ./
dockerfile: ./docker/yourservice/Dockerfile
Unfortunately, (for practical and security reasons I guess), if you want to add/copy local content, it must be located under the same root path than the Dockerfile
.
From the documentation:
The <src> path must be inside the context of the build; you cannot ADD ../something/something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.
EDIT: There's now an option (-f
) to set the path of your Dockerfile ; it can be used to achieve what you want, see @Boedy 's response.