user2608576
user2608576

Reputation: 807

Create non root user in Docker Alpine images with lesser image size?

I am using docker node node:alpine for building the container but i would like to start my node application as non root user. Just adding the user and group using adduser and addgroup is increasing the size of image by 300MB compared to when running as root user.

Using shadow from alpine testing repo also does the same (i.e. increases the size of my image by 300MB). RUN echo http://nl.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories

Any tools or any suggestions how to create non root user with considerably not increasing the size of image too much ?

Upvotes: 2

Views: 4805

Answers (2)

Tobias Gurtzick
Tobias Gurtzick

Reputation: 46

Since I can't comment, please by all means ignore the answer of Sergey Yarotskiy. This is a dangerous misleading answer, which is also wrong.

Read for example https://medium.com/@mccode/processes-in-containers-should-not-run-as-root-2feae3f0df3b to why you should NEVER run as root in your containers unless you really explicitly need to.

However you can instead run your container with docker run -u to specify the user manually.

Upvotes: 2

yamenk
yamenk

Reputation: 51738

One solution is to switch the storage driver from aufs to device mapper as described here.

Alternatively, another solution is to directly copy the resources from the host and set the owner in the same COPY instruction

COPY [--chown=<user>:<group>] <src>... <dest>

Upvotes: 2

Related Questions