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 2 commits
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
25 changes: 8 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
FROM golang:1.9
FROM golang:1.9-alpine

RUN apk add --no-cache git libcap shadow
RUN useradd -ms /bin/bash freegeoip
COPY cmd/freegeoip/public /var/www

ADD . /go/src/github.com/apilayer/freegeoip
WORKDIR /go/src/github.com/apilayer/freegeoip/cmd/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
go get -d && \
go install && \
setcap cap_net_bind_service=+ep /go/bin/freegeoip

USER freegeoip
ENTRYPOINT ["/go/bin/freegeoip"]
USER freegeoip

EXPOSE 8080

Copy link
Author

@justgage justgage Feb 27, 2018

Choose a reason for hiding this comment

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

I deleted these comments because I don't think they were bringing much value, however I can put them back due to that being outside the scope of this PR

Choose a reason for hiding this comment

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

@justgage there is a great Dockerfile best practices article here. I thought I would pass it along.
https://docs.docker.com/develop/develop-images/dockerfile_best-practices/

Following these recommendations, specifically for RUN, it will create a more readable Dockerfile:

FROM golang:1.9-alpine

RUN apk add --no-cache \
    git \
    libcap \
    shadow \
 && addgroup -g 1000 -S freegeoip \
 && adduser -u 1000 -S freegeoip -G freegeoip

COPY cmd/freegeoip/public /var/www
COPY . /go/src/github.com/apilayer/freegeoip

WORKDIR /go/src/github.com/apilayer/freegeoip/cmd/freegeoip

RUN go get -d \
 && go install \
 && setcap cap_net_bind_service=+ep /go/bin/freegeoip

ENTRYPOINT ["/go/bin/freegeoip"]
USER freegeoip

EXPOSE 8080

Notice that the ADD was changed to a COPY as per the recommendation here on transparency.

# CMD instructions:
# Add "-use-x-forwarded-for" if your server is behind a reverse proxy
# Add "-public", "/var/www" to enable the web front-end
# Add "-internal-server", "8888" to enable the pprof+metrics server
#
# Example:
# CMD ["-use-x-forwarded-for", "-public", "/var/www", "-internal-server", "8888"]