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"]