Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

279
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda