Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Use alpine docker file #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Dockerfile
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
Copy link

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.

Copy link
Author

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.

RUN go get -d
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not group all of these RUNs into one layer like the existing image?

Copy link
Author

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A rebuild produced this error

Step 10/13 : RUN useradd -ms /bin/bash freegeoip
 ---> Running in afcee3ec8484
Creating mailbox file: No such file or directory

but otherwise image rebuilt and installed OK fully functioning on :80
still outstanding issue on :443 #3

Copy link
Author

Choose a reason for hiding this comment

The 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)?

Choose a reason for hiding this comment

The 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:

RUN \
      addgroup -g 1000 -S freegeoip && \
      adduser -u 1000 -S freegeoip -G freegeoip

The base image golang:1.9-alpine is currently running 3.6.2, but this still seems to correctly create the home directory:

echo $HOME
/home/freegeoip

Copy link
Author

Choose a reason for hiding this comment

The 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"]
Expand Down