Dockerfile:
FROM golang:latest WORKDIR /app ADD . . RUN go env -w GOPROXY=https://goproxy.io,direct RUN go get RUN go build -o app . CMD ["/app/app"]
zzh@ZZHPC:/zdata/MyPrograms/Go/aaa$ docker build -t test:v1 . [+] Building 1.3s (3/3) FINISHED docker:default => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 126B 0.0s => ERROR [internal] load metadata for docker.io/library/golang:latest 1.3s ------ > [internal] load metadata for docker.io/library/golang:latest: ------ Dockerfile:1 -------------------- 1 | >>> FROM golang:latest 2 | WORKDIR /app 3 | ADD . . -------------------- ERROR: failed to solve: golang:latest: error getting credentials - err: exec: "docker-credential-desktop": executable file not found in $PATH, out: ``
This is because I only installed docker in my Ubuntu and don't have docker desktop.
Deleting below line
"credsStore": "desktop",
from ~/.docker/config.json can fix this issue.
zzh@ZZHPC:/zdata/MyPrograms/Go/aaa$ docker build -t test:v1 . [+] Building 11.4s (11/11) FINISHED docker:default => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 176B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/golang:latest 2.6s => [1/6] FROM docker.io/library/golang:latest@sha256:c416ceeec1cdf037b80baef1ccb402c230ab83a9134b34c0902c542eb4539c82 0.0s => [internal] load build context 0.0s => => transferring context: 254B 0.0s => CACHED [2/6] WORKDIR /app 0.0s => [3/6] ADD . . 0.0s => [4/6] RUN go env -w GOPROXY=https://goproxy.io,direct 0.2s => [5/6] RUN go get 2.0s => [6/6] RUN go build -o app . 6.3s => exporting to image 0.3s => => exporting layers 0.3s => => writing image sha256:f42bb07f7315ebe8c1637fd56cef227ab658f4f9455b34e82104e7d1e8ae7cd0 0.0s => => naming to docker.io/library/test:v1 0.0s
The final argument right at the back of the Docker build command from the preceding is not a typo. That is an important argument that is needed to indicate the folder, which we would use as a reference for the Dockerfile to build it from. In most
cases, Dockerfiles tend to be at the root of subprojects, and the current symbol of “.” indicates the current directory is usually the correct parameter to use in most cases.