Skip to content

Instantly share code, notes, and snippets.

@JfrAziz
Created April 9, 2022 21:59
Show Gist options
  • Save JfrAziz/1a0473e6a7442ca8f19af9cd3873c05f to your computer and use it in GitHub Desktop.
Save JfrAziz/1a0473e6a7442ca8f19af9cd3873c05f to your computer and use it in GitHub Desktop.
some random docker compose
version: '3'
volumes:
db:
name: ${DB_CONTAINER:-postgres}
services:
postgres:
image: postgres:alpine
container_name: ${DB_CONTAINER:-postgres}
restart: always
environment:
- POSTGRES_USER=${DB_USERNAME:-postgres}
- POSTGRES_PASSWORD=${DB_PASSWORD:-secret}
- POSTGRES_DB=${DB_DATABASE:-postgres}
volumes:
- db:/var/lib/postgresql/data
ports:
- 5432:5432
#!/bin/bash
ERROR_FILE="/tmp/docker-images-update.error"
# make sure that docker is running
DOCKER_INFO_OUTPUT=$(docker info 2> /dev/null | grep "Containers:" | awk '{print $1}')
if [ "$DOCKER_INFO_OUTPUT" == "Containers:" ]
then
echo "Docker is running, so we can continue"
else
echo "Docker is not running, exiting"
exit 1
fi
# get a list of docker images that are currently installed
IMAGES_WITH_TAGS=$(docker images | grep -v REPOSITORY | grep -v TAG | grep -v "<none>" | awk '{printf("%s:%s\n", $1, $2)}')
# run docker pull on all of the images
for IMAGE in $IMAGES_WITH_TAGS; do
echo "*****"
echo "Updating $IMAGE"
docker pull $IMAGE 2> $ERROR_FILE
if [ $? != 0 ]; then
ERROR=$(cat $ERROR_FILE | grep "not found")
if [ "$ERROR" != "" ]; then
echo "WARNING: Docker image $IMAGE not found in repository, skipping"
else
echo "ERROR: docker pull failed on image - $IMAGE"
fi
fi
echo "*****"
echo
done
# did everything finish correctly? Then we can exit
echo "Docker images are now up to date"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment