$ sudo groupadd docker
Optionally change the username to match your preferred user.
$ sudo gpasswd -a $USER docker
IMPORTANT: Log out and log back in so that your group membership is re-evaluated.
$ sudo service docker restart
If you are on Ubuntu 14.04-15.10, use docker.io
instead:
$ sudo service docker.io restart
If you installed Docker Desktop first, then removed it and installed the Docker Engine, you may need to switch the Docker context with this command:
$ docker context use default
Because Docker Desktop switches context before startups and shutdowns not to interfere Docker Engine. So context might be kept incorrectly after removing Docker Desktop. A related article: https://www.howtogeek.com/devops/how-to-troubleshoot-cannot-connect-to-the-docker-daemon-errors/
https://stackoverflow.com/questions/73671461/docker-not-working-without-sudo-in-ubuntu-22-04