linux update
Below are two methods for updating the project: Custom Upgrade Steps (my preferred approach) and Official Upgrade Steps.
Custom Upgrade Steps
1 Switch to the Latest Tag
- Sync all remote tags:bash
git fetch --tags
- View available tags
- git tag
- Switch to the desired tag
- git checkout tags/0.14.0
2 Back up the docker-compose.yaml
file
- Create a backup of the
docker-compose.yaml
file:bash
cp docker-compose.yaml docker-compose.yaml.$(date +%Y%m%d%H%M%S).bak
3 Stop the Services
- Navigate to the
docker
directory and stop the services:bash
cd dify/docker
docker compose -p dify down
4 Back Up the Entire Project
- Create a compressed backup of the data volumes:bash
tar -cvf volumes-$(date +%Y%m%d%H%M%S).tgz volumes
5 Check for Changes in the .env
File
After downloading the latest code, compare the new .env
file with the current one to identify any new or updated environment variables. Update configurations as needed.
6 Start the Project
- Restart the updated services:bash
docker compose -p dify up -d
Official Upgrade Steps
1 Back up your customized docker-compose YAML file (optional)
cd docker
cp docker-compose.yaml docker-compose.yaml.$(date +%s).bak
2 Get the latest code from the main branch
git checkout main
git pull origin main
3 Stop the service,Command, please execute in the docker directory
docker compose down
4 Back up data
tar -cvf volumes-$(date +%s).tgz volumes
5 Upgrade services
docker compose up -d
window update
Upgrade step by step
1 Back up your customized docker-compose YAML file (optional)
# Switch to the docker directory
Set-Location -Path .\docker
# Get the current timestamp (format: yyyyMMddHHmmss)
$timestamp = Get-Date -Format "yyyyMMddHHmmss"
# Copy and back up the docker-compose.yaml file
Copy-Item -Path .\docker-compose.yaml -Destination "docker-compose.yaml.$timestamp.bak"
2 Get the latest code from the main branch
# Switch to the main branch
git checkout main
# Pull the latest code from the remote repository
git pull origin main
3 Stop the service,Command, please execute in the docker directory
# Stop all services managed by docker-compose
docker compose down
4 Back up data
# Get the current timestamp
$timestamp = Get-Date -Format "yyyyMMddHHmmss"
# Compress the volumes directory using tar
tar -cvf "volumes-$timestamp.tgz" .\volumes
5 Upgrade services
# Start all services and run them in the background
docker compose up -d
full PowerSehll
# Switch to the docker directory
Set-Location -Path .\docker
# Back up the docker-compose.yaml file
$timestamp = Get-Date -Format "yyyyMMddHHmmss"
Copy-Item -Path .\docker-compose.yaml -Destination "docker-compose.yaml.$timestamp.bak"
# Update the code from the main branch
git checkout main
git pull origin main
# Stop the currently running services
docker compose down
# Back up the volumes data
tar -cvf "volumes-$timestamp.tgz" .\volumes
# Start or update the services
docker compose up -d
Usage:
- Open PowerShell.
- Save the above script as a
.ps1
file, for example,update-docker.ps1
. - Navigate to the directory where the script is saved in PowerShell.
- Execute the script:powershell
.\update-docker.ps1
Important Notes:
- Ensure that the PowerShell execution policy allows running scripts. You can temporarily change the execution policy with the following command:powershell
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
Using cmd.exe
@echo off
REM Switch to the docker directory
cd docker
REM Get the current timestamp
for /f "tokens=1 delims=." %%a in ('powershell -NoProfile -Command "Get-Date -Format yyyyMMddHHmmss"') do set timestamp=%%a
REM Back up the docker-compose.yaml file
copy docker-compose.yaml docker-compose.yaml.%timestamp%.bak
REM Update the code from the main branch
git checkout main
git pull origin main
REM Stop the currently running services
docker compose down
REM Back up the volumes data
tar -cvf volumes-%timestamp%.tgz volumes
REM Start or update the services
docker compose up -d