Copy failed in simple build project

Hey all, I’m trying to use balena build to build a project. My use case is that I need to make local edits to the container before it’s pushed/deployed to balena cloud. I had some issues creating a working container based off of the balenalib/ base images using plain docker, so figured I would try yo use balena build instead.

My docker-compose.yml file is as follows:

version: "2"

        build: ./myproject
            - "9099:9099"

While my Dockerfile (of course under ./myproject/) is as follows:

FROM balenalib/amd64-ubuntu:jammy-run

RUN     apt-get update && \
        apt-get install -y unzip

COPY ~/myprojectsrc/linux/amd64/ ./

RUN unzip -d myproject

RUN chmod +x ./myproject/*.sh

CMD ["/bin/bash", "/myproject/"]

balena build doesn’t complain initially and downloads and installs the unzip util. However, after that the build errors out with the following message:

[Error]   Build failed.
COPY failed: file not found in build context or excluded by .dockerignore: stat ~/myprojectsrc/linux/amd64/ file does not exist

Not sure what exactly is going on - the COPY works perfectly running under normal Docker. And when I move the file to the Dockerfile’s local directory (./myproject), I instead get:

[Error]   Build failed.
Array buffer allocation failed

I believe the COPY command source refers to an absolute path within the build context, not an absolute path on the host. In other words, you should try moving into the myproject directory and remove the path information from the COPY command.

Hey, I’ve faced a similar issue when using balena build before. The “file not found” issue might be related to the way balena build is handling the build context. Unlike vanilla Docker, it might not be able to resolve the ~ in the path.

You can try to use an absolute path for the COPY command to see if that resolves the issue. Or, as you said, you can keep the file in the same directory as the Dockerfile and use a relative path. It’s weird that even that didn’t work, though.

If the COPY command works in normal Docker but not in balena build, it could be worth checking if .dockerignore is playing a role here, even though the error suggests otherwise.

Have you also tried running balena build with the --debug option to see if you get more detailed logs? Could be helpful for pinpointing the issue.

Hope that helps! Keep us posted on how it goes.