'Docker-Compose Building back unable to prepare context: unable to evaluate symlinks in Dockerfile path

I have the following dir structure:

.
├── docker-compose.yml
├── README.md
└── services
    ├── api
    │   ├── Dockerfile
    │   └── src
    │       ├── app.py
    │       ├── settings.py
    │       └── .env
    └── recorder
        ├── Dockerfile
        ├── Pipfile
        ├── Pipfile.lock
        ├── .env
        └── src

The dockerfile contains

version: '3'
services:

  back:
    build: 
      dockerfile: services/api/Dockerfile
      context: services/api/
    ports:
      - '5001:5001'
    env_file:
      - services/api/.env

  recorder:
    build: 
      dockerfile: services/recorder/Dockerfile
      context: services/recorder/
    ports:
      - '5002:5002'
    env_file:
      - services/recorder/.env

And when I execute

docker-compose up -d --no-deps --build

or

docker-compose up -d

or

docker-compose up back

I always get

Building back unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat > /home/juser/VideoCapturer/services/api/services: no such file or directory

I don't understand why docker appends the last '/services' to the path too.

Any idea about how can I solve this?

Thanks



Solution 1:[1]

The Dockerfile is relative to the context when using compose. It's a bit inconsistent to the way docker CLI behaves, but it is what it is.

In your case you could simplify it anyway:

services:
  back:
    build: ./services/api
  recorder:
    build: ./services/recorder

If you wanted to provide file and context, the as mentioned the Dockerfile needs to be relative to the context.

services:
  back:
    build: 
      context: ./services/api
      dockerfile: ./Dockerfile
  recorder:
      context: ./services/recorder
      dockerfile: ./Dockerfile

This would be only required if the file wasn't named Dockerfile and/or is not in the context directory. So in this case, you can use the short form from above.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1