I got a docker-compose file in which I want to set a context and docker file to look something like this:
build:
context: <path to context>
dockerfile: <path to dockerfile>
For now my file is in the root folder so its simply:
build:
context: .
dockerfile: .
This way it does work.
The structure of the project is something like this:
./
- folder1/
- folder2/
docker-compose.yaml
DockerFile
I want to copy files as part of the commands in the DockerFile and I want the paths to be relative to the root folder of the project.
How with this project structure do I set the context to be the root folder of the project? I tried doing context: ../../ but I then got an error:
Error response from daemon: unexpected error reading Dockerfile: read (path): is a directory
How do I set the context correctly?
You've set:
dockerfile: .
Just try to use a relative path to you Dockerfile from the set context:
context: ../../
dockerfile: ./folder1/folder2/Dockerfile
You cannot change the context to be a parent folder, you can read it about it in the docker-compose documentation. https://docs.docker.com/compose/compose-file/compose-file-v3/#context
what you can do is have the composefile in the folder which in the the highest hierarchy and change the context accordingly. like so:
version: "3.7"
services:
srv2:
build:
dockerfile: src/services/srv2/Dockerfile
context: ./
image: srv2
srv1:
build:
dockerfile: src/services/srv1/Dockerfile
context: ./
image: srv1
or you can make the context the directory of the service that contains the Dockerfile of the service
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With