docker - 在 docker 容器中安装 golang 外部包

标签 docker go docker-compose

我正在尝试在 golang 中获取一个外部库,但是当我在命令下触发时:

FROM golang:1.8-alpine
RUN go get gopkg.in/natefinch/lumberjack.v2
EXPOSE 8080

它给出以下错误:

go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/gin-gonic/gin: exec: "git": executable file not found in $PATH

我正在使用 golang:1.8-alpine。请帮忙解决这个问题。

最佳答案

错误说你没有 git 作为基础镜像的一部分

"git": executable file not found in $PATH

安装它

FROM golang:1.8-alpine
RUN apk update && apk add git && go get gopkg.in/natefinch/lumberjack.v2
EXPOSE 8080

然后当你构建它应该没问题

docker build .
Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM golang:1.8-alpine
 ---> 4cb86d3661bf
Step 2/3 : RUN apk update && apk add git && go get gopkg.in/natefinch/lumberjack.v2
 ---> Running in 8f4b12af99af
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/community/x86_64/APKINDEX.tar.gz
v3.5.2-356-ga384f1f9b9 [http://dl-cdn.alpinelinux.org/alpine/v3.5/main]
v3.5.2-348-gf3907a61f6 [http://dl-cdn.alpinelinux.org/alpine/v3.5/community]
OK: 7964 distinct packages available
(1/5) Installing libssh2 (1.7.0-r2)
(2/5) Installing libcurl (7.61.0-r0)
(3/5) Installing expat (2.2.0-r1)
(4/5) Installing pcre (8.39-r0)
(5/5) Installing git (2.11.3-r1)
Executing busybox-1.25.1-r1.trigger
OK: 28 MiB in 17 packages
Removing intermediate container 8f4b12af99af
 ---> d8d5badecd71
Step 3/3 : EXPOSE 8080
 ---> Running in 0ebd5797b55e
Removing intermediate container 0ebd5797b55e
 ---> 7187901edcf4
Successfully built 7187901edcf4

关于docker - 在 docker 容器中安装 golang 外部包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51686129/

相关文章:

azure - 在 Docker Swarm 中挂载 Azure 存储

http - 如何使用 Go 代理 https 请求,http 请求工作正常?

http-post - 使用 HTTP Post 并使用 Cookie

wordpress - Wordpress Docker容器无法连接到数据库容器

mongodb - 无法解决 MongoParseError : Invalid connection string

docker - 从 docker 容器内部连接到主机网络上的 IP 地址

docker - 使用 Docker-compose 在云部署中进行分布式 memcached

docker - 从 docker 容器内进行端口转发

docker - 来自守护进程 : Get http s://registry-1. docker.io/v2/的错误响应:proxyconnect tcp:tls:第一条记录看起来不像 TLS 握手

GoLang 复制命令准备好的语句不工作