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.
The error is in your
docker-compose.yamlfile. In version 1 of that format, you can specify bothbuildanddockerfile. If you provide both, thedockerfileattribute denotes the file name that is expected to be found in the directory specified bybuild.In your case, change the
dockerfileattribute to just include the filename instead of the same path as inbuild:Since
Dockerfileis the default name, you can also simply remove this line: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
buildparameter.