Skip to content

Commit 6058140

Browse files
authored
fix permission issues with Dockerfile nonroot implementation (#333)
1 parent c06d416 commit 6058140

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

Dockerfile

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# get golang container
2-
FROM golang:1.22.1
2+
FROM golang:1.22.1 AS builder
33

44
# get args
55
ARG TibiaDataBuildBuilder=dockerfile
@@ -23,23 +23,24 @@ RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags="-w -s -X '
2323

2424

2525
# get alpine container
26-
FROM alpine:3.19.1
26+
FROM alpine:3.19.1 AS app
2727

28-
# create nonroot user
29-
RUN addgroup -S nonroot \
30-
&& adduser -S nonroot -G nonroot
28+
# create workdir
29+
WORKDIR /opt/app
3130

32-
# add ca-certificates
31+
# add ca-certificates and tzdata
3332
RUN apk --no-cache add ca-certificates tzdata
3433

35-
# create workdir
36-
WORKDIR /root/
34+
# create nonroot user and group
35+
RUN addgroup -S nonroot && \
36+
adduser -S nonroot -G nonroot && \
37+
chown -R nonroot:nonroot .
3738

38-
# copy binary from first container
39-
COPY --from=0 /go/src/app .
39+
# set user to nonroot
40+
USER nonroot:nonroot
4041

41-
# set user
42-
USER nonroot
42+
# copy binary from builder
43+
COPY --from=builder --chown=nonroot:nonroot --chmod=544 /go/src/app .
4344

4445
# expose port 8080
4546
EXPOSE 8080

0 commit comments

Comments
 (0)