Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install golang external packages in docker container

I am trying to get an external library in golang but when i fire below command :

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

it gives below error:

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

I am using golang:1.8-alpine. Please help how to fix this.

like image 811
Nirmal Vatsyayan Avatar asked Aug 04 '18 13:08

Nirmal Vatsyayan


1 Answers

The error says that you don't have git as part of the base image

"git": executable file not found in $PATH

Install it

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

then when you build it should be fine

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
like image 76
Sathyajith Bhat Avatar answered Nov 07 '22 14:11

Sathyajith Bhat