简体   繁体   中英

Building Docker image as non-root user

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 ?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM