How to login to a running Docker container as root?
TL DR:
docker exec -it --user root <container> bash
-----------------------------------------------
Most of the times the application would run in a different user. as specified in the docker file. Such a docker file is mentioned below.
FROM openjdk:17-alpine
RUN apk update && apk add --no-cache gcompat && apk add curl bash
RUN addgroup -S appuser && adduser -S appuser -G appuser
USER appuser:appuser
# some custom code to run an app
In this Dockerfile the line "USER appuser:appuser" specifies the user and group which the application should run. Also, any commands following this line will run as the same user, and if you login the container without specifying the user explicitly, it will be the default user.
eg:
Docker exec accepts another parameter to specify the user. With that we can login as root or any user we want.
Comments
Post a Comment