There is one rectification in the backend-service.dockerfile, RUN mkdir /app is not required, the line WORKDIR /app will create app directory if it doesn't exists.
Also, after WORKDIR /app command gets executed it will change to the newly created directory so, COPY backendApp /app can also be written as COPY backendApp .
COPY backendApp /app is also fine.
Now coming to the no such file or directory error, the alpine docker image is very minimalist Linux image.
alpine Linux image doesn't comes with standard runtime libraries needed by your backendApp executable, you need to find out the runtime dependencies and add/install into your alpine Linux image using backend-service.dockerfile.
Refer the example below to get a bit more of understanding:
This is the file structure of the directory
Dockers$ tree
.
├── backend-service
│ ├── backendApp
│ ├── backendApp.c
│ └── backend-service.dockerfile
└── docker-compose.yml
2 directories, 4 files
As you can see there is a backendApp.c file, with just a simple Hello World! print statement in a while(1) loop and backendApp is the compiled binary.
The contents of respective backend-service.dockerfile is shown below:
FROM alpine:latest
WORKDIR /app
COPY backendApp .
CMD [ "/app/backendApp" ]
The docker-compose.yml is exactly same as yours, now after running docker-compose build I get the output image:
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
dockers-backend-service latest bbd272015851 22 minutes ago 7.07MB
And if I run it, I get the exact same error as yours
docker run dockers-backend-service
exec /app/backendApp: no such file or directory
Now here the problem is that the backendApp is a C program which needs libc6 library which is not part of alpine Linux image and that's why the error.
To resolve this I just have to add RUN apk add libc6-compat in backend-service.dockerfile and re-build the image and it will resolve the runtime dependency of backendApp binary
$ docker run dockers-backend-service
Hello Docker Compose!!
I hope this answers your Question!