Skip to content

Commit

Permalink
[Loki]: Cleanup dockerfile (#1949)
Browse files Browse the repository at this point in the history
* Reduce the amount of layers and data in the Dockerfile

* Change the loki user and data directory to match the default helm configuration

* Add an nsswitch.conf to stop localhost DNS requests

* Copy changes to Dockerfile.cross except setep

setep is probably not needed anymore due to 3100 being the default
port. Also, I'm not sure the amd64 binary works on other arch
binaries.

* Install ca-certificates earlier and split creating user and creating dir steps

* Install libcap earlier and don't bother deleting it as it doesn't make the image smaller

* Revert config changes

* Revert the dockerfile changes needed for the config revert
  • Loading branch information
SerialVelocity authored Apr 23, 2020
1 parent e60164b commit 97788ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
13 changes: 7 additions & 6 deletions cmd/loki/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ WORKDIR /src/loki
RUN make clean && (if [ "${TOUCH_PROTOS}" ]; then make touch-protos; fi) && make BUILD_IN_CONTAINER=false loki

FROM alpine:3.9
RUN apk add --update --no-cache ca-certificates libcap \
&& rm -rf /var/cache/apk/*

RUN apk add --no-cache ca-certificates libcap

COPY --from=build /src/loki/cmd/loki/loki /usr/bin/loki
COPY cmd/loki/loki-docker-config.yaml /etc/loki/local-config.yaml

RUN setcap cap_net_bind_service=+ep /usr/bin/loki

RUN apk del --no-cache libcap && rm -rf /var/cache/apk/*

RUN addgroup -g 1000 -S loki && \
adduser -u 1000 -S loki -G loki
RUN addgroup -g 10001 -S loki && \
adduser -u 10001 -S loki -G loki
RUN mkdir -p /loki && \
chown -R loki:loki /etc/loki /loki

# See https://github.com/grafana/loki/issues/1928
RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf

USER loki
EXPOSE 3100
ENTRYPOINT [ "/usr/bin/loki" ]
Expand Down
16 changes: 14 additions & 2 deletions cmd/loki/Dockerfile.cross
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,21 @@ WORKDIR /src/loki
RUN make clean && GOARCH=$(cat /goarch) GOARM=$(cat /goarm) make BUILD_IN_CONTAINER=false loki

FROM alpine:3.9
RUN apk add --update --no-cache ca-certificates

RUN apk add --no-cache ca-certificates

COPY --from=build /src/loki/cmd/loki/loki /usr/bin/loki
COPY cmd/loki/loki-local-config.yaml /etc/loki/local-config.yaml
EXPOSE 80

RUN addgroup -g 10001 -S loki && \
adduser -u 10001 -S loki -G loki
RUN mkdir -p /loki && \
chown -R loki:loki /etc/loki /loki

# See https://github.com/grafana/loki/issues/1928
RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf

USER loki
EXPOSE 3100
ENTRYPOINT [ "/usr/bin/loki" ]
CMD ["-config.file=/etc/loki/local-config.yaml"]

0 comments on commit 97788ab

Please sign in to comment.