Dockerfile – How to copy files from a local folder?

Below is the Dockerfile:

FROM golang:1.14.10

COPY ~/go/bin/product-api /go/bin/product-api

COPY ~/go/bin/swagger /go/bin/swagger

ENTRYPOINT ["/go/bin/product-api"]

on docker build -t cloud-native-product-api:1.0.0 ., gives error:

Step 3/5 : COPY ~/go/bin/product-api /go/bin/product-api
COPY failed: stat /var/lib/docker/tmp/docker-builder398080099/~/go/bin/product-api: no such file or directory

I think the image build process takes /var/lib/docker/tmp/docker-builder398080099 as workspace and refer from that path.

How to copy files from specific folder of local machine into Docker image?

Source: Docker Questions