Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the "current" directory of a Dockerfile with Docker Compose?

Tags:

docker

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)?

like image 493
ddinchev Avatar asked May 07 '16 10:05

ddinchev


1 Answers

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.

like image 57
johnharris85 Avatar answered Nov 08 '22 09:11

johnharris85