What's the default user for docker exec?

Beau Barker picture Beau Barker · Aug 29, 2018 · Viewed 27.6k times · Source

Is root the default user when calling docker exec (without --user)?

Does a USER line in the Dockerfile affect the default user for docker exec?

Answer

BMitch picture BMitch · Aug 29, 2018

The default user in docker exec is the same user used to start the container which can be set in docker run or your compose file.

If you do not explicitly set the user when starting the container, it will default to the user configured in the image, you can inspect the image to look this up. This is configured by the last USER line in the Dockerfile. It may also be configured by a parent image specified by the FROM line.

If neither the image, nor the run command specifies a user, docker defaults to root, uid 0.