Skip to content

Instantly share code, notes, and snippets.

@tsuz
Last active February 14, 2021 12:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsuz/08f84647eea856bc1e2f136130955579 to your computer and use it in GitHub Desktop.
Save tsuz/08f84647eea856bc1e2f136130955579 to your computer and use it in GitHub Desktop.
Example of adding local timezone into Docker (example for Asia/Tokyo) - Dockerに日本時間を導入する方法
############################
# STEP 1 build executable binary
############################
FROM golang:1.11-alpine as builder
ARG SSH_PRIVATE_KEY
RUN apk update \
&& apk add openssh \
&& apk add git mercurial \
&& apk add bash \
&& apk add -U --no-cache ca-certificates \
&& rm -rf /var/cache/apk/*
# Get JST timezone data
RUN apk --no-cache add tzdata && \
cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
# Create working directory
RUN mkdir -p /go/src/my-app
WORKDIR /go/src/my-app
COPY . .
RUN mkdir -p ~/.ssh && umask 0077 && echo "${SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa \
&& echo "Host gitlab.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config \
&& touch ~/.ssh/known_hosts \
&& ssh-keyscan gitlab.com >> ~/.ssh/known_hosts \
&& git config --global url."git@gitlab.com:".insteadOf https://gitlab.com/ \
&& ssh-keyscan github.com >> ~/.ssh/known_hosts
# using dep
RUN go get -u -v github.com/golang/dep/cmd/dep
RUN dep ensure -v
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -a -installsuffix cgo -o /go/bin/my-app .
RUN apk del git mercurial
############################
# STEP 2 build a small image
############################
FROM scratch
# Copy our static executable.
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /go/bin/my-app /go/bin/my-app
COPY --from=builder /etc/passwd /etc/passwd
ADD https://github.com/golang/go/raw/master/lib/time/zoneinfo.zip /usr/local/go/lib/time/zoneinfo.zip
# Use a privileged user.
USER root
# Run the binary
ENTRYPOINT ["/go/bin/my-app"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment