I have the following project structure:
.
..
project/
docker/cli/Dockerfile
docker-compose.yml
In docker-compose.yml I have the following configuration:
cli:
build: docker/cli
And somewhere in my Dockerfile:
COPY . /app
Now the problem is that when I do docker-compose build cli docker copies the contents of docker/cli/ in /app in my image. Which makes sense because that is the relative path to my docker/cli/Dockerfile. Is there a way however to tell in my docker-compose.yml config that the path should be different (namely the root dir of my project where the actual project files are)?
You can use the context attribute of a build instruction inside the docker-compose file.
version: '2'
services:
cli:
build:
context: .
dockerfile: docker/cli/Dockerfile
This should work as desired. The context is what is sent to the docker daemon for build. You will also want a .dockerignore file in your project directory though, to ensure only what you need is sent.
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