Skip to content

Commit

Permalink
Ensure Go binaries use /etc/hosts first.
Browse files Browse the repository at this point in the history
Go <1.16 has unexpected default behavior when the /etc/nsswitch.conf
file is missing: It will default to making a network request before
looking in local files like /etc/hosts. Unfortunately the very popular
alpine images do not have /etc/nsswitch.conf by default and so we must
create one ourselves.

There are many reports of this causing issues with name resolution:

golang/go#22846
golang/go#35305

Until this is fixed in a released version of Go (hopefully 1.16) we need
this change to ensure lookups happen in the expected way (files and then
network).

Change-Id: I246a767ae2767f0f83bf3b4229938a292cf9737e
  • Loading branch information
calebcase committed Jan 15, 2021
1 parent 80bd6a6 commit 7b2987b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/authservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ VOLUME /root/.local/share/storj/authservice
HEALTHCHECK --interval=10s --timeout=3s --start-period=5s \
CMD ["/app/authservice", "--log.level=error", "health-check"]

RUN echo 'hosts: files dns' > /etc/nsswitch.conf
COPY release/${TAG}/authservice_linux_${GOARCH:-amd64} /app/authservice
COPY cmd/authservice/entrypoint /entrypoint

Expand Down
8 changes: 8 additions & 0 deletions cmd/gateway-mt/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
ARG DOCKER_ARCH
FROM ${DOCKER_ARCH:-amd64}/alpine

ARG TAG
ARG GOARCH

ENV GOARCH ${GOARCH}

EXPOSE 7777
WORKDIR /app

VOLUME /root/.local/share/storj/gateway-mt

RUN echo 'hosts: files dns' > /etc/nsswitch.conf
COPY release/${TAG}/gateway-mt_linux_${GOARCH:-amd64} /app/gateway-mt
COPY cmd/gateway-mt/entrypoint /entrypoint

ENTRYPOINT ["/entrypoint"]

ENV STORJ_CONFIG_DIR=/root/.local/share/storj/gateway-mt
ENV STORJ_SERVER_ADDRESS=0.0.0.0:7777

0 comments on commit 7b2987b

Please sign in to comment.