SoFunction
Updated on 2025-03-09

Use the docker command without typing sudo

Since docker daemon needs to be bound to the Unix socket of the host instead of the ordinary TCP port, and the owner of the Unix socket is the root user, other users can only perform related operations if they add the sudo option before the command.

If you don't want to use the docker command to click on sudo, you can configure it according to the following method.

1. Create a docker group

$ sudo groupadd docker

2. Add the current user to the docker group

$ sudo usermod -aG docker $USER

3. Log out and log in to the shell again

4. Verify whether the docker command can run

$ docker run hello-world

Supplementary knowledge:Docker image acceleration

After installing Docker, you will have fun playing, but the actual situation is not pleasant.

Because docker's default image source is abroad, due to the special network reasons in China, it is often slow to access or cannot be accessed at all. Fortunately, there are similar image sources in China that can be used. I use the image source provided by daocloud, and the experience is pretty good.

What's convenient is that they provide a script to modify the mirror source with one click, the specific commands are as follows:

curl -sSL /daotools/set_mirror.sh | sh -s

After executing the above command, docker's default image source points to daocloud's image repository. At this time, the docker service needs to be restarted to take effect.

sudo systemctl restart

Try pulling a mirror

$ docker pull busybox

If the image is downloaded smoothly, it means that the above modification has taken effect.

Reference official website

The above article that does not require typing sudo using docker command is all the content I share with you. I hope it can give you a reference and I hope you support me more.