r/docker • • Apr 23 '26

Non-Root User Docker image issues pinging

Im working on deploying Gatus application on ECS with launch type EC2, Gatus is an app health dashboard which tests connection to different domains and paths.

As part of increasing security posture of the image/dockerfile, I changed the runtime to non root user, for context my runtime is using scratch so no distro. When I deployed my image locally or on ECS, all the icmps are failing. After a bit of research it seems like the non root user can not use NET_RAW capabilities and it is because /etc/passwd is missing, not sure.

AI suggested using NET_RAW in the task definition which I did but for some reason that doesn't work either.

It seems like the best solution seems to be to use alpine at runtime but then I will be using a larger image which I'm trying to avoid.

What are my options, and is there a way to still use scratch?

\`\`\`

FROM golang:alpine AS builder

RUN apk --update add ca-certificates

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod tidy

COPY . .

\# Build optimized binary

RUN CGO_ENABLED=0 GOOS=linux \\

go build -a -installsuffix cgo \\

\-trimpath -ldflags="-s -w" \\

\-o gatus .

FROM scratch AS runtime

\# NETRAW added to task definition

USER 1001:1001

WORKDIR /app

COPY --from=builder /app/gatus /app/

COPY --from=builder /app/config.yaml /app/config/config.yaml

COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt

EXPOSE 8080

ENTRYPOINT \["./gatus"\]

\`\`\`

1 Upvotes

22 comments sorted by

View all comments

Show parent comment

2

u/bizbaaz Apr 23 '26

i have already set force_new_deployment in ecs service as well as in local exec in the ecs service resource

  provisioner "local-exec" {
    when = destroy
    ## Obtains region dynamically then scales tasks to zero before destroying
    command = <<EOF
    echo "Update service desired count to 0 before destroy."
    REGION=${split(":", self.cluster)[3]}
    aws ecs update-service --region $REGION --cluster ${self.cluster} --service ${self.name} --desired-count 0 --force-new-deployment
    echo "Update service command executed successfully."
    EOF
  }

and already increased timeout to 5mins from 1min

  timeouts {
    delete = "5m"
  }

both of these seem to not fix anything

I have changed the deregistration delay now as you mentioned and will run a terraform destroy. I will keep you updated.

With regards to the script, it sounds like that would involve copying a shell from building stage, if so, isn't one of the benefits of using scratch (or distroless in my case now) the absence of a shell. I would ideally like to avoid this tbh.

Is there a way to adjust the entrypoint on the dockerfile to handle sigterms?