ZhangZhihui's Blog  

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.

posted on   ZhangZhihuiAAA  阅读(683)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
 
点击右上角即可分享
微信分享提示