0

I'm creating an Azure VM image using Packer. The VM is just a Debian 10 installation with a couple of packages installed.

What I really need to do is to add VM admin user to a specific unix group (docker).

During the packer image provisioning I make changes to the /etc/adduser.conf to enable extra groups:

  "provisioners": [{
    "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'",
    "inline": [
      "apt-get update",
      "apt-get upgrade -y",
      "apt-get -y install docker.io",
      "echo 'ADD_EXTRA_GROUPS=1\nEXTRA_GROUPS=\"docker\"' >> /etc/adduser.conf",

      "/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync"
    ],
    "inline_shebang": "/bin/sh -x",
    "type": "shell"
  }]

But it only adds explicitly created users to the docker group but the the admin users created with the following command:

az vm create \
    --resource-group myResourceGroup \
    --name myVM \
    --image myPackerImage \
    --admin-username azureuser \
    --generate-ssh-keys

Is there any way to add admin user to the group docker too?

6
  • Maybe I misunderstand what you need, but I think you might need to look at /etc/group for that. – schaiba Oct 26 '19 at 8:47
  • If you just want to add a user to the docker group, perhaps you want usermod -Ga docker -l <username> – Bruce Becker Oct 27 '19 at 5:58
  • @BruceBecker the problem is that the <username> is unknown because it is all performed on the image provisioning stage. – Petr Razumov Oct 28 '19 at 6:05
  • 1
    From what I understand waagent doesn't actually use adduser hence why changes to /etc/adduser.conf doesn't work. – Richard Slater Oct 30 '19 at 17:03
  • 1
    Actually that link shows it uses ‘useradd’, adduser is an abstraction over useradd, unfortunately its adduser that reads the adduser.conf. – Richard Slater Nov 15 '19 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.