-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
49 lines (36 loc) · 1.62 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
FROM golang:1.13.0-stretch AS builder
ENV GO111MODULE=on \
CGO_ENABLED=0
WORKDIR /build
# Let's cache modules retrieval - those don't change so often
COPY go.mod .
#COPY go.sum .
RUN go mod download
# Copy the code necessary to build the application
# You may want to change this to copy only what you actually need.
COPY . .
# Build the application
RUN go build ./cmd/icndb-server
# Let's create a /dist folder containing just the files necessary for runtime.
# Later, it will be copied as the / (root) of the output image.
WORKDIR /dist
RUN cp /build/icndb-server ./icndb-server
# Optional: in case your application uses dynamic linking (often the case with CGO),
# this will collect dependent libraries so they're later copied to the final image
# NOTE: make sure you honor the license terms of the libraries you copy and distribute
#RUN ldd my-awesome-go-program | tr -s '[:blank:]' '\n' | grep '^/' | \
# xargs -I % sh -c 'mkdir -p $(dirname ./%); cp % ./%;'
#RUN mkdir -p lib64 && cp /lib64/ld-linux-x86-64.so.2 lib64/
# Copy or create other directories/files your app needs during runtime.
# E.g. this example uses /data as a working directory that would probably
# be bound to a perstistent dir when running the container normally
RUN cp -r /build/templates ./templates
# Create the minimal runtime image
FROM scratch
COPY --chown=0:0 --from=builder /dist /
# Set up the app to run as a non-root user inside the /data folder
# User ID 65534 is usually user 'nobody'.
# The executor of this image should still specify a user during setup.
#COPY --chown=65534:0 --from=builder /data /data
#USER 65534
ENTRYPOINT ["/icndb-server"]