Docker-compose: always receive Cannot locate specified Dockerfile

1k Views Asked by At

I have a following project structure:

WebApp
  -- docker-compose.yml
  -- Dockerfile
  -- docker
     -- docker-gc
        --Dockerfile

docker/docker-gc is a git submodule that I have created before using this command:

 git submodule add [email protected]:spotify/docker-gc.git docker/docker-gc

in docker-compose, I try to run Dockerfile in docker-gc. Here is my service:

gc:
  container_name: docker-gc
  build: ./docker/docker-gc
  dockerfile: ./docker/docker-gc/Dockerfile
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    - /etc:/etc

But I always receive error:

Cannot locate specified Dockerfile ./docker/docker-gc/Dockerfile

I have tried many ways such as docker/docker-gc/Dockerfile or /docker/docker-gc/Dockerfile without result. Is this problem related to symlink (due to git submodule nature). Please tell me how can I fix this.

2

There are 2 best solutions below

1
On BEST ANSWER

The error is in your docker-compose.yaml file. In version 1 of that format, you can specify both build and dockerfile. If you provide both, the dockerfile attribute denotes the file name that is expected to be found in the directory specified by build.

In your case, change the dockerfile attribute to just include the filename instead of the same path as in build:

gc:
  container_name: docker-gc
  build: ./docker/docker-gc
  dockerfile: Dockerfile
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    - /etc:/etc

Since Dockerfile is the default name, you can also simply remove this line:

gc:
  container_name: docker-gc
  build: ./docker/docker-gc
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    - /etc:/etc

Please refer to the Docker Compose documentation for more info.

Please also note that version 2 of the Docker Compose file format uses a different notion of the build parameter.

0
On

Try to do it without Dockerfile in the end. The default should be that it uses a file called "Dockerfile" in the specified folder.