# Docker

### On compute module :

```bash
mkdir -p /mnt/ssd/docker/data
mkdir -p /mnt/ssd/docker/compose
```

```
sudo apt update && sudo apt install apt-transport-https ca-certificates curl wget gnupg lsb-release -y

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt update && sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-compose -y
```

### Version courte :

```
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $(whoami)
newgrp docker
docker run hello-world
```

##### Relocate /var/lib/docker

```bash
#Stop docker
sudo systemctl stop docker.service
sudo systemctl stop docker.socket

# Move data to SSD
sudo rsync -aP /var/lib/docker/ /mnt/ssd/docker/data/

# Edit docker config
sudo vim /etc/docker/daemon.json
```
```bash
{ 
  "data-root": "/mnt/ssd/docker/data",
  "log-driver": "local",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}
```

```bash
# Restart docker
sudo systemctl start docker.socket
sudo systemctl start docker.service

# Verify...
sudo systemctl status docker
sudo docker info | grep "Docker Root Dir"

# Delete old data folder
sudo rm -rf /var/lib/docker/
```

Fix docker error loading config file if necessary
```bash
sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "/home/$USER/.docker" -R
```
