Skip to content

Commit

Permalink
Updated script to pull Portainer's exact release
Browse files Browse the repository at this point in the history
Adjusted the Portainer container setup script to fetch the latest release tag from GitHub and use this specific tag when pulling the image. This ensures the container is set up with the correct Portainer version, avoiding inconsistencies that occur with the ':latest' tag. Removed redundant digest-based image version check for clarity and efficiency. The script now reliably pulls and runs the most recent Portainer release version.

Fixes issues with outdated container versions when using ':latest' tag.
  • Loading branch information
yousecjoe committed Apr 27, 2024
1 parent a6c1e1a commit 04367e7
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/docker/containers/portainer/docker-run-portainer.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
echo "Starting the script!"

# Check GitHub for latest release version
curl -s https://api.github.com/repos/portainer/portainer/releases/latest | jq -r '.tag_name'
ghVersion=$(curl -s https://api.github.com/repos/portainer/portainer/releases/latest | jq -r '.tag_name')

# Check Docker Hub for latest Docker image version
imageSource=portainer/portainer-ce:latest
docker pull $imageSource
docker image inspect $imageSource | jq -r '.[].RepoDigests[]' | awk -F@ '{print $2}'
imageSource=portainer/portainer-ce:"$ghVersion"
docker pull "$imageSource"
docker image inspect "$imageSource" | jq -r '.[].RepoDigests[]' | awk -F@ '{print $2}'
# shellcheck disable=SC1035
digest=$(!!)
version=$(curl -s 'https://hub.docker.com/v2/repositories/portainer/portainer-ce/tags' -H 'Content-Type: application/json' | jq -r '.results[] | select(.digest == "'"$digest"'") | .name' | sed -n 2p)
#digest=$(!!)
#version=$(curl -s 'https://hub.docker.com/v2/repositories/portainer/portainer-ce/tags' -H 'Content-Type: application/json' | jq -r '.results[] | select(.digest == "'"$digest"'") | .name' | sed -n 2p)


# Setup container using specific tag, because the :latest tag does not always pull down the latest version
echo "Pulling Docker image..."
docker pull portainer/portainer-ce:"$version"
docker pull portainer/portainer-ce:"$ghVersion"

# Shutting down the stack
#echo "Shutting down the stack..."
Expand Down Expand Up @@ -62,7 +62,7 @@ docker run -itd \
--restart=unless-stopped \
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data \
portainer/portainer-ce:"$version"
portainer/portainer-ce:"$ghVersion"

# Notify the user the script has completed.
echo "Script has finished!"

0 comments on commit 04367e7

Please sign in to comment.