$ sudo groupadd dockerOptionally change the username to match your preferred user.
$ sudo gpasswd -a $USER dockerIMPORTANT: Log out and log back in so that your group membership is re-evaluated.
$ sudo service docker restartIf you are on Ubuntu 14.04-15.10, use docker.io instead:
$ sudo service docker.io restartIf 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 defaultBecause 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