Running Docker and Docker Compose commands without
sudo is a common request, especially for development environments. Note the Security Implications. Here’s how to set it up:
Table of Contents
Best answer: Add the user to the
By default, the Docker daemon binds to a Unix socket instead of a TCP port. The Unix socket is owned by the user
root and other users can only access it using
sudo. The Docker daemon always runs as the
If you don’t want to use
sudo it when you use the Docker command, create a Unix group called
docker and add users to it. When the Docker daemon starts, it makes the ownership of the Unix socket read/writable by the
sudo usermod -aG docker $USER
$USER with your username if it doesn’t work directly.
Log out and log back in
This ensures your user is running with the correct permissions.
Test the Docker command without
Run the following:
docker run hello-world
This should download and run the
hello-world Docker image, which simply prints a greeting and exits.
Test Docker Compose without
Just try any
docker-compose command, for example:
docker-compose --version or docker compose version // for v2
This should display the version of Docker Compose installed.
Do note that being a part of the
docker group is equivalent to having root access. This is because Docker containers can be used to gain root access to the host system. Ensure you trust the members of the
docker group and be cautious about the images and containers you run.
Remember, if you’re using a cloud environment or an environment where others might have access, understand the risks before implementing these changes. Always consider security implications when adjusting permissions.