Last active
March 27, 2022 18:06
-
-
Save mchurichi/17c51c0f6fdd676bdbfb9e10502417a9 to your computer and use it in GitHub Desktop.
Docker & Kubernetes snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Copy docker images from a registry to another one given a pattern | |
#!/bin/bash | |
SRC_REGISTRY=localhost:5000 | |
DST_REGISTRY=public.ecr.aws/xxxxxxx | |
NEW_TAG=latest | |
docker images --format "{{.ID}} {{.Repository}}" | while read line; do | |
pieces=($line) | |
if [[ "${pieces[1]}" == *"${SRC_REGISTRY}"* ]]; then | |
IMAGE_NAME=$(echo "${pieces[1]}" | sed -e "s|^${SRC_REGISTRY}/||") | |
NEW_IMAGE_NAME="${DST_REGISTRY}/${IMAGE_NAME}:${NEW_TAG}" | |
docker tag "${pieces[0]}" $NEW_IMAGE_NAME | |
docker push $NEW_IMAGE_NAME | |
fi | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Docker Compose service wait for postgresql db to be up and ready accepting connections | |
version: '3.4' | |
services: | |
web: | |
image: my-web-app | |
build: | |
context: . | |
dockerfile: Dockerfile | |
depends_on: | |
# wait for dependency to be healthy, as defined in the dependency healthcheck | |
db: | |
condition: service_healthy | |
db: | |
image: postgres:12.4-alpine | |
ports: | |
- 5432:5432 | |
volumes: | |
- ./db/data:/var/lib/postgresql/data | |
environment: | |
POSTGRES_DB: ${DB_NAME} | |
POSTGRES_USER: ${DB_USER} | |
POSTGRES_PASSWORD: ${DB_PASSWORD} | |
# run the healthcheck every 5 seconds (5s timeout) up to 10 times | |
healthcheck: | |
test: "psql --list -U $DB_USER" | |
interval: 5s | |
timeout: 5s | |
retries: 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment