dockerdocker-compose

Docker-compose: build could not find Dockerfile


/path/
   web/
      Dockerfile
      docker-compose.yml
   file.zip

docker-compose.yml

version: "3"
services:
  
  web:
    container_name: web
    build:
      context: ..
      dockerfile: Dockerfile
    tags:
      - "test/example1:latest"

Run docker compose:

> cd /path/web
> docker-compose up

failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount1535462816/Dockerfile: no such file or directory

If building the image from command line directly, it works.

cd /path/web
docker build -f Dockerfile test/example1:latest ..

Solution

  • Use dockerfile: web/Dockerfile

    The dockerfile specifies an alternative file to build with. Since you use context as .., the docker daemon will use .. as the build context and the Dockerfile will use /path/web as it's root for file path references with the Dockerfile in /path/web/Dockerfile as the alternate Dockerfile.