---
# System prepended metadata

title: Docker Install (non-root user)
tags: [Docker, Advanced]

---

Docker Install (non-root user)
===
預設docker是以`root`當作user及group
因此一般的user需要管理員權限(sudo)，才能有docker權限
將user加入docker group，使得user能有docker的權限，免除sudo
1. **創建docker群組**
```bash!
sudo groupadd docker
```
2. **將user加入docker group**
```bash!
sudo usermod -aG docker $USER
```
3. **安裝docker**

使用 `apt` 安裝
```bash!
sudo apt update
sudo apt install ca-certificates curl
```
```bash
sudo install -m 0755 -d /etc/apt/keyrings \
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc \
sudo chmod a+r /etc/apt/keyrings/docker.asc
```
```bash
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
```
```bash!
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
```
4. **重新啟動**
5. **在terminal打 `docker info` 如果沒有出現 Error，代表 user 可以直接有 docker 的權限了，也就是不用 `sudo`**
