I am trying to follow this post, adding the current user to the Docker group:
sudo usermod -aG docker $(whoami)
but of course, there is no usermod command on macOS:
-bash: usermod: command not found
Now I was wondering if there is an equivalent of the above command on macOS? Probably using dscl?
P.S.1. I have used these instructions to set up Docker and docker-machine.
P.S.2. This question is not about Visual Studio Code (VSCode)
in particular, but if I open a new terminal and run eval "$(docker-machine env default)" and then run VSCode with code the problem is solved.
This question, as others have also pointed out, is irrelevant. The process of adding a user to the docker group is only necessary on Linux where sudo privileges are required to run Docker commands, as explained here. On macOS, and using docker-machine, that is unnecessary.
But if one wants to add a user, or more specifically the current user, to the docker user group, for whatever reason, here are the instructions:
dscl . list /groups from heresudo dscl . create /Groups/<groupName> from here.<groupName> could be replaced with docker.sudo dseditgroup -o edit -a <userName> -t user <groupName>. from here or sudo dscl . append /Groups/<groupName> GroupMembership <userName> from here.<userName> with $USER or $(whoami) to refer to the current user.dscl . -read /Groups/<groupName> GroupMembership to list all the remembers. However, it is not guaranteed to deliver the correct result, as explained here.And the another issue with the Visual Studio Code, also has barely anything to do with the user groups. By running the eval "$(docker-machine env <dockerMachineName>)" in a new terminal, and running the code editor from inside the terminal, the Docker extension works just fine.
I also had to write sudo on macOS to run docker commands (I don't know why). Thanks to Foad's explanation, I fixed it.
I just want to add commands which are ready for use. The first one creates a docker group. The second one adds the current users to the docker group.
sudo dscl . create /Groups/docker
sudo dseditgroup -o edit -a $USER -t user docker
If you need something different, read Foad S. Farimani's answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With