-
Notifications
You must be signed in to change notification settings - Fork 201
Use alpine docker file #1
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
FROM golang:1.9 | ||
FROM golang:1.9-alpine | ||
|
||
COPY cmd/freegeoip/public /var/www | ||
|
||
ADD . /go/src/github.com/apilayer/freegeoip | ||
RUN \ | ||
cd /go/src/github.com/apilayer/freegeoip/cmd/freegeoip && \ | ||
go get -d && go install && \ | ||
apt-get update && apt-get install -y libcap2-bin && \ | ||
setcap cap_net_bind_service=+ep /go/bin/freegeoip && \ | ||
apt-get clean && rm -rf /var/lib/apt/lists/* && \ | ||
useradd -ms /bin/bash freegeoip | ||
WORKDIR /go/src/github.com/apilayer/freegeoip/cmd/freegeoip | ||
RUN apk update | ||
RUN apk add git libcap shadow | ||
RUN go get -d | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not group all of these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Splitting it up (from my limited knowlege) allows if you change the lower ones the upper ones will be cached, meaning you won't have to run the higher ones nearly as often. Perhaps I missunderstood that though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my most recent PR I've organized it so that it should cache installing the depenecies (changes infrequently). I found what helped the most was moving the COPY down. However It seems from this discussion that there's tradofs of caching for file size differences: https://stackoverflow.com/questions/39223249/multiple-run-vs-single-chained-run-in-dockerfile-what-is-better There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A rebuild produced this error
but otherwise image rebuilt and installed OK fully functioning on :80 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I looked up that error hoping I could fix it, however after my reserach it seemed like there wasn't a great way to fix it, and it doesn't cause issues. I could create the directory that it's trying to access but I was afraid that would only add to the image size (not sure of that though)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to this ticket, mhart/alpine-node#48, the correct way to add a user in Apline 3.7 is:
The base image
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. followed @dsperling advice, seems the errors are gone @OlagStegan |
||
RUN go install | ||
RUN setcap cap_net_bind_service=+ep /go/bin/freegeoip | ||
RUN useradd -ms /bin/bash freegeoip | ||
|
||
USER freegeoip | ||
ENTRYPOINT ["/go/bin/freegeoip"] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RUN apk add --no-cache git libcap shadow
Removes the need to run
apk update
and to remove package lists after.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Didn't know that.