# Updating Guide

# Updating Portainer on Docker Standalone

This guide will walk you trough updating Portainer in terminal. Always match the agent version to the Portainer Server version. In other words, when you're installing or updating to Portainer 2.27.9 make sure all of the agents are also on version 2.27.9.

To update to the latest version of Portainer Server, use the following commands to stop then remove the old version. Your other applications/containers will not be removed.

[Portainer Documentation](https://docs.portainer.io/start/upgrade)

##### Updating Portainer

1. SSH to main Portainer machine (Overseer)
2. Run Following Commands

```bash
docker stop portainer
```

```bash
docker rm portainer
```

```bash
docker pull portainer/portainer-ce:lts
```

```bash
docker run -d -p 8000:8000 -p 9443:9443 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:lts
```

This will stop and remove old version and reinstalled new on. The newest version of Portainer will now be deployed on your system, using the persistent data from the previous version, and will also upgrade the Portainer database to the new version.

Updating Portainer Agent

1. SSH to vms that run portainer agents (External vm, Internal vm)
2. Run Following Commands

```bash
docker stop portainer_agent
```

```bash
docker rm portainer_agent
```

```bash
docker pull portainer/agent:lts
```

```bash
docker run -d -p 9001:9001 --name portainer_agent --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker/volumes:/var/lib/docker/volumes portainer/agent:lts
```

# Updating Authentik

This is extended guide to updating Authentik software. Read trough official Authentik documentation before running updates.

[Authentik Documentation](https://docs.goauthentik.io/install-config/upgrade/)

1. Take a snapshot of Overseer vm
2. Navigate to Authentik Directory

```bash
cd /docker/authentik
```

3. Backup Database

```bash
docker exec -t authentik_postgresql_1 pg_dumpall -c -U postgres > authentik_backup.sql
```

4. Download the latest docker-compose.yml file

```bash
wget -O docker-compose.yml https://goauthentik.io/docker-compose.yml
```

5. Ensure .env is all set and has following variables in it

```bash
touch .env
```

```yaml
PG_PASS=your_database_password
PG_USER=authentik
PG_DB=authentik
AUTHENTIK_SECRET_KEY=your_secret_key
AUTHENTIK_TAG=latest
```

6. Pull the Latest image and apply the updates

```bash
docker compose pull
docker compose up -d
```

7. Check the status

```bash
docker compose ps
```

8. Login to Authentik and make sure everything is up to date, and everything is working properly

Optional:

If there is an error due to space when downloading or installing the image run a clean up command:

```bash
docker image prune -a
```

# Update Docker Compose Tool

To update Docker Compose to new v2 version follow these steps:

1. Add Docker GPG Key

```bash
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
```

2. Add Docker Repository

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

3. Install Docker Compose

```bash
sudo apt-get update
sudo apt-get install docker-compose-plugin
```

To check the version

```bash
docker compose version
```