How to set the "current" directory of a Docker file using Docker Compose?

I have the following project structure:

.
..
project/
docker/cli/Dockerfile
docker-compose.yml

In docker-compose.ymlI have the following configuration:

cli:
  build: docker/cli

And somewhere in my Docker file:

COPY . /app

Now the problem is that when I do docker-compose build cli, dockers copy the contents docker/cli/in /appon my image. This makes sense because it is a relative path to mine docker/cli/Dockerfile. Is there a way to tell in my configuration docker-compose.ymlthat the path should be different (namely, the root directory of my project, where are the actual project files)?

+4
source share
1 answer

You can use the contextinstruction attribute in the docker-compose file build.

version: '2'
services:
  cli:
    build: 
      context: .
      dockerfile: docker/cli/Dockerfile

. context - , docker . .dockerignore project, , , .

+10

All Articles