I had a problem where I couldn't open a Docker container in VSCode so I tried this example and it also failed. I tried a very simple example then posted the results here https://askubuntu.com/questions/1551001/why-is-docker-build-failing and got a reply indicating that the snap install of Docker is unable to access /tmp:
canonical/docker-snap#34 (comment)
When I uninstalled the snap version and used apt-get it worked:
https://docs.docker.com/engine/install/ubuntu/
You should change from using /tmp in your build.