Skip to content

Use numeric UID in Dockerfiles for better container security#1624

Merged
gugu merged 1 commit into
mainfrom
docker-numeric-uid
Feb 22, 2026
Merged

Use numeric UID in Dockerfiles for better container security#1624
gugu merged 1 commit into
mainfrom
docker-numeric-uid

Conversation

@gugu

@gugu gugu commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

Kubernetes runAsNonRoot and other container runtimes may require numeric UIDs. Switch USER directives to UID 1001 across all Dockerfiles.

Kubernetes runAsNonRoot and other container runtimes may require
numeric UIDs. Switch USER directives to UID 1001 across all Dockerfiles.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 22, 2026 14:45
@gugu gugu enabled auto-merge (squash) February 22, 2026 14:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates container user configuration to use a fixed numeric UID (1001) so images are compatible with Kubernetes runAsNonRoot and similar runtime policies.

Changes:

  • Switch USER directives to numeric UID 1001.
  • Pin created appuser UID/GID to 1001 in Debian-based images.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
autoadmin-ws-server/Dockerfile Runs the service as numeric UID 1001 (instead of named user).
Dockerfile.rocketadmin-agent Pins appuser to UID/GID 1001 and runs as UID 1001.
Dockerfile Pins appuser to UID/GID 1001 and runs as UID 1001.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

COPY --from=builder /app/dist ./dist

USER nodejs
USER 1001

Copilot AI Feb 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using USER 1001 sets only the UID; depending on the container runtime, the GID may default to 0 (root) when the group isn’t specified. To keep the process out of the root group and match the created nodejs group (GID 1001), set the directive explicitly to USER 1001:1001 (or USER nodejs:nodejs).

Suggested change
USER 1001
USER nodejs:nodejs

Copilot uses AI. Check for mistakes.
RUN chown -R appuser:appuser /app

USER appuser
USER 1001

Copilot AI Feb 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

USER 1001 sets only the UID; some runtimes may default the primary GID to 0 (root) if it isn’t specified. Since you’re creating appuser with GID 1001, use USER 1001:1001 to ensure the container doesn’t run in the root group and to avoid group-based permission surprises.

Suggested change
USER 1001
USER 1001:1001

Copilot uses AI. Check for mistakes.
Comment thread Dockerfile
RUN chown -R appuser:appuser /run

USER appuser
USER 1001

Copilot AI Feb 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

USER 1001 sets only the UID; the effective GID can default to 0 (root) when the group isn’t provided, which is a security footgun and can cause unexpected permission behavior. Since appuser is created with GID 1001, prefer USER 1001:1001 here.

Suggested change
USER 1001
USER 1001:1001

Copilot uses AI. Check for mistakes.
@gugu gugu merged commit 9593c67 into main Feb 22, 2026
21 of 23 checks passed
@gugu gugu deleted the docker-numeric-uid branch February 22, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants