Reputation: 5986
When building a Docker image, as a best practice, I understand I should not use the root
user but I'm having a hard time with the user I created.
Here my Dockerfile
FROM alpine:3.9.2
RUN addgroup -S cetacean && adduser -S mobydick -G cetacean
USER mobydick
RUN apk update
And Here the error I get when I run it
ERROR: Unable to lock database: Permission denied
ERROR: Failed to open apk database: Permission denied
What am I supposed to do in order to be able to install packages using mobydick
?
Upvotes: 2
Views: 9412
Reputation: 391
As per best practices, if possible we should run docker container as non-root user.
We can do that by adding the user at the end so that you can install all the packages as root and when container starts, it uses non-root user.
FROM alpine:3.9.2
RUN addgroup -S cetacean && adduser -S mobydick -G cetacean
RUN apk update
USER mobydick
You can read more here.
Upvotes: 6