docker-compose build errors on COPY

I’m running Docker Desktop on Windows 10. I have a folder on my desktop with the structure:

├── cab/
│ ├── backend/
│ │ ├── Dockerfile
│ │ └── (the rest of my backend java application) 
│ ├── frontend/
│ │ ├── Dockerfile
│ │ └── (the rest of my frontend react application) 
│ ├── mysql/
│ │ ├── Dockerfile
│ │ ├── schema.sql
│ │ └── data.sql
│ └── docker-compose.yml

My docker-compose.yml file looks like this:

services:
    mysql:
        build: 
            context: .
            dockerfile: ./mysql/Dockerfile
        ports:
            - "3306:3306"
        networks:
            - cab-booking
    cab-frontend:
        build: 
            context: .
            dockerfile: ./frontend/Dockerfile
        ports:
            - "3000:3000"
        networks:
            - cab-booking
    cab-backend:
        build: 
            context: .
            dockerfile: ./backend/Dockerfile
        ports:
            - "8080:8080"
        networks:
            - cab-booking

networks:
    cab-booking:

And this is my Dockerfile in frontend/:

FROM node:18-alpine
WORKDIR /home/cab-frontend

COPY package.json /home/cab-frontend/
RUN npm install

COPY public/ /home/cab-frontend/public
COPY src/ /home/cab-frontend/src

CMD ["npm", "start"]

When I run docker-compose build, I get this error output:

2024/05/06 15:12:58 http2: server: error reading preface from client //./pipe/docker_engine: file has already been closed
2024/05/06 15:12:58 http2: server: error reading preface from client //./pipe/docker_engine: file has already been closed
2024/05/06 15:12:58 http2: server: error reading preface from client //./pipe/docker_engine: file has already been closed
[+] Building 0.0s (0/0)  docker:default
2024/05/06 15:12:58 http2: server: error reading preface from client //./pipe/docker_engine: file has already been closed
2024/05/06 15:12:58 http2: server: error reading preface from client //./pipe/docker_engine: file has already been close[+] Building 0.9s (26/33)                                                                                docker:default
 => [cab-backend internal] load build definition from Dockerfile                                                   0.0s
 => => transferring dockerfile: 540B                                                                               0.0s
 => [mysql internal] load build definition from Dockerfile                                                         0.0s
 => => transferring dockerfile: 311B                                                                               0.0s
 => [cab-backend internal] load metadata for docker.io/library/openjdk:21-jdk-slim                                 0.8s
 => [cab-backend internal] load metadata for docker.io/library/maven:3.9.6-amazoncorretto-21-al2023                0.8s
 => [cab-frontend internal] load build definition from Dockerfile                                                  0.0s
 => => transferring dockerfile: 246B                                                                               0.0s
 => [mysql internal] load metadata for docker.io/library/mysql:8-oracle                                            0.0s
 => [mysql internal] load .dockerignore                                                                            0.0s
 => => transferring context: 2B                                                                                    0.0s
 => [cab-frontend internal] load metadata for docker.io/library/node:18-alpine                                     0.7s
 => CACHED [mysql 1/4] FROM docker.io/library/mysql:8-oracle                                                       0.0s
 => [mysql internal] load build context                                                                            0.0s
 => => transferring context: 369B                                                                                  0.0s
 => [mysql 2/4] COPY . .                                                                                           0.1s
 => [mysql 3/4] ADD schema.sql /docker-entrypoint-initdb.d                                                         0.1s
 => [mysql 4/4] ADD data.sql /docker-entrypoint-initdb.d                                                           0.1s
 => [mysql] exporting to image                                                                                     0.1s
 => => exporting layers                                                                                            0.1s
 => => writing image sha256:6da7f28843817809bf2083f8e5b70c979458f25465f8f22c148f507a0ae63667                       0.0s
 => => naming to docker.io/library/cab-mysql                                                                       0.0s
 => [cab-frontend internal] load .dockerignore                                                                     0.0s
 => => transferring context: 2B                                                                                    0.0s
 => [cab-backend internal] load .dockerignore                                                                      0.0s
 => => transferring context: 2B                                                                                    0.0s
 => [cab-frontend internal] load build context                                                                     0.0s
 => => transferring context: 2B                                                                                    0.0s
 => [cab-frontend 1/6] FROM docker.io/library/node:18-alpine@sha256:4837c2ac8998cf172f5892fb45f229c328e4824c43c85  0.0s
 => [cab-backend build 1/7] FROM docker.io/library/maven:3.9.6-amazoncorretto-21-al2023@sha256:8d653ed25358201bdb  0.0s
 => CANCELED [cab-backend internal] load build context                                                             0.1s
 => => transferring context: 136.38kB                                                                              0.0s
 => [cab-backend stage-1 1/2] FROM docker.io/library/openjdk:21-jdk-slim@sha256:7072053847a8a05d7f3a14ebc778a90b3  0.0s
 => CACHED [cab-frontend 2/6] WORKDIR /home/cab-frontend                                                           0.0s
 => ERROR [cab-frontend 3/6] COPY package.json /home/cab-frontend/                                                 0.0s
 => CACHED [cab-frontend 4/6] RUN npm install                                                                      0.0s
 => ERROR [cab-frontend 5/6] COPY public/ /home/cab-frontend/public                                                0.0s
 => ERROR [cab-frontend 6/6] COPY src/ /home/cab-frontend/src                                                      0.0s
------
 > [cab-frontend 3/6] COPY package.json /home/cab-frontend/:
------
------
 > [cab-frontend 5/6] COPY public/ /home/cab-frontend/public:
------
------
 > [cab-frontend 6/6] COPY src/ /home/cab-frontend/src:
------
failed to solve: failed to compute cache key: failed to calculate checksum of ref 2f1ad847-6c62-4f2a-91c3-e58ef7209d25::ibusmsuotmr2zt8ktmd9hc1dt: "/src": not found

I’m not sure what these errors mean – neither the http2 server error at the top of the output, nor the blank output for COPY, nor the “/src” not found. What do I do?

It turned out the error was with my context parameters. I had to change my docker-compose.yml file to look like this:

services:
    mysql:
        build: 
            context: ./mysql
            dockerfile: ./Dockerfile
        ports:
            - "3306:3306"
        networks:
            - cab-booking
    cab-frontend:
        build: 
            context: ./frontend
            dockerfile: ./Dockerfile
        ports:
            - "3000:3000"
        networks:
            - cab-booking
    cab-backend:
        build: 
            context: ./backend
            dockerfile: ./Dockerfile
        ports:
            - "8080:8080"
        networks:
            - cab-booking

networks:
    cab-booking:

To paraphrase someone helping me: Docker runs in the / directory. But my frontend Dockerfile was putting files in the /home/cab-frontend/ directory.
context: ./mysql is like telling docker compose to cd to mysql before running the dockerfile.
context: . would be fine if your dockerfiles were all sitting in your root directory.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật