It looks like you have BuildKit enabled in your docker configuration. BuildKit can cause these type of problems. Please try it again with BuildKit disabled.
In Linux, using environment variables:
export DOCKER_BUILDKIT=0
export COMPOSE_DOCKER_CLI_BUILD=0
In Windows and macOS, start the Docker Desktop application, go to Settings, select Docker Engine and look for the existing entry:
"buildkit": true
Change this entry to disable buildkit:
"buildkit": false
Then click on Apply & Restart and try it again.