The Docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user `root` and other users can only access it using `sudo`. The Docker daemon always runs as the `root` user.
If you don’t want to preface the docker
command with sudo
, create a Unix group called docker
and add users to it. When the Docker daemon starts, it creates a Unix socket accessible by members of the docker
group.
- 建立
docker
使用者組sudo groupadd docker
- 新增你想用普通使用者許可權的使用者名稱到
docker
使用者組sudo usermod -aG docker $USE
- 系統重啟後就可以使用普通使用者許可權執行
docker
, 如果不想重啟,可以使用下面的命令更新並啟用組許可權newgrp docker
- 驗證設定是否成功
docker run hello-world
如果出現下面錯誤提示,建議重啟電腦:WARNING: Error loading config file: /home/user/.docker/config.json - stat /home/user/.docker/config.json: permission denied
本作品採用《CC 協議》,轉載必須註明作者和本文連結