Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

273
Views
How do I add a container user to a user group in the Docker host?

I'm currently experimenting on Docker specifically on the aspect where a user inside given container affects the Docker host itself. Ultimately, I want the user to be able to run containers on its very own host from inside its container. It kind of sounds a little absurd, but I'm hoping it works.

At the moment, I'm looking for a way for that given user to be part of the Docker host's docker group. Is there a way to do that?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

From the perspective of the Docker host, any users inside the container are treated exactly the same as a user outside the container with the same UID (not the same name!), regardless of whether the UID is actually in use on the host. Unfortunately, it appears that only users with a username can belong to groups, so you can't just add the UID to the group. Instead, you need to add the host user with the same UID to the group (or create a user with that UID if one doesn't exist).

over 4 years ago · Santiago Trujillo Report

0

I wrote a bash script to generate dockerfiles on the fly with the current user added on the container and the docker group. Here is the meat of it:

# get the current user's info
user=$USER
uid=`id -u $user`
gid=`id -g $user`

# get gid for group docker
RESULT=$(id -g docker 2>&1)
if [ 1 -ne $? ] ; then
    docker_gid=$RESULT
fi

echo FROM ubuntu:14.04

echo MAINTAINER Nobody "no-reply@nothere.com"

echo USER root
echo "RUN apt-get update && apt-get -y install docker-engine"
echo "RUN /bin/bash -c 'getent passwd ${user} || \
    adduser --system --gid ${gid} ${docker_group} --uid ${uid} --shell /bin/bash ${user} || \
    usermod -l ${user} \$(getent passwd ${uid} | cut -d: -f1)'"

if [ -n "$docker_gid" ] ; then
    echo "RUN /bin/bash -c 'getent group docker && groupmod --gid ${docker_gid} docker \
        || groupadd --gid ${docker_gid} docker'"
    echo "RUN /bin/bash -c 'groups ${user} | grep docker || usermod --groups ${docker_gid} ${user}'"
fi

HTH!

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!