Build ERROR: ERROR: failed to solve: failed to compute cache key: failed to "": not found

Docker says that this Golang file my_custom_api.go is not found, but it is does exist. I’m running docker build that contains the Dockerfile from the pwd ./build/package.
Does Docker disike copying files outside of the root directory or something, or is it something fishy going on with how docker interprets the context?

Project Directory
.
├── ./api
│   └── ./api/my_custom_api.go
├── ./app.go
├── ./build
│   ├── ./build/package
│   │   └── ./build/package/Dockerfile
│   └── ./build/README.md
├── ./fly.toml
├── ./go.mod
└── ./go.sum 

- Dockerfile
# Stage 1: Download pre-built PocketBase binary
FROM alpine:latest AS pocketbase-downloader

# Set the PocketBase version
ENV POCKETBASE_VERSION=0.22.20

# Set up working directory
WORKDIR /app

RUN wget https://github.com/pocketbase/pocketbase/releases/download/v${POCKETBASE_VERSION}/pocketbase_${POCKETBASE_VERSION}_linux_amd64.zip \
    && unzip pocketbase_${POCKETBASE_VERSION}_linux_amd64.zip \
    && rm pocketbase_${POCKETBASE_VERSION}_linux_amd64.zip

# Copy your custom Go code into the PocketBase source directory
COPY ../../api/my_custom_api.go /app/pocketbase/api/my_custom_api.go
COPY ../.. /app/pocketbase/app.go

# Build the custom PocketBase binary
WORKDIR /app/pocketbase
RUN ls -al /app/pocketbase

RUN go mod tidy
RUN go build -o /pocketbase ./app.go

# Stage 2: Create a minimal final image
FROM alpine:latest

# Copy pre-built PocketBase binary
COPY --from=pocketbase-downloader /pocketbase /usr/local/bin/pocketbase

# Expose the default PocketBase port
EXPOSE 8080

# Command to run PocketBase in the container
CMD ["pocketbase", "serve", "--http=0.0.0.0:8080"]

Files and directories can be copied from the build context, …

So yes, files have to be in the build context. That’s the one you set as the argument of docker build.

If you don’t want to change your filestructure and don’t want to add all the files to your build context either running docker build from the project root, you can run a script instead of docker build directly and copy files into a temporary folder. If you actually ran the docker build command from the project root, then the Dockerfile has to refer to the files relatively from the project root