linuxdockercontainersbusybox

Docker Busybox container add groups and user


I need users in my docker containers. My build is from the busybox image which is missing groupadd, I tried to add it using apt-get but that's also missing. What do I need to add to my Dockerfile to get groupadd?

So far I have

FROM busybox
RUN apt-get install bash
RUN groupadd -r postgres && useradd -r -g postgres postgres
CMD /bin/sh

Solution

  • You're trying to run Debian based command on a non-Debian system. If you need apt-get and other tools like that, you should change your base image with a FROM debian.

    Busybox does include the addgroup with the following syntax:

    / # addgroup --help
    BusyBox v1.24.2 (2016-03-18 16:38:06 UTC) multi-call binary.
    
    Usage: addgroup [-g GID] [-S] [USER] GROUP
    
    Add a group or add a user to a group
    
        -g GID  Group id
        -S  Create a system group