在Docker容器中安装Golang外部软件包

时间:2018-08-04 13:35:52

标签: 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。请帮助解决此问题。

1 个答案:

答案 0 :(得分:5)

错误很明显,您在基本图片中没有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