Last active
June 24, 2024 20:36
-
-
Save didip/ff5088fd023624aba7c0 to your computer and use it in GitHub Desktop.
Small helper script that automates Docker building and pushing
This file contains 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
#!/bin/bash | |
set -ex | |
PARENT_DIR=$(basename "${PWD%/*}") | |
CURRENT_DIR="${PWD##*/}" | |
IMAGE_NAME="$PARENT_DIR/$CURRENT_DIR" | |
TAG="${1}" | |
REGISTRY="hub.docker.com" | |
docker build -t ${REGISTRY}/${IMAGE_NAME}:${TAG} . | |
docker tag ${REGISTRY}/${IMAGE_NAME}:${TAG} ${REGISTRY}/${IMAGE_NAME}:latest | |
docker push ${REGISTRY}/${IMAGE_NAME} | |
docker tag ${REGISTRY}/${IMAGE_NAME}:latest ${REGISTRY}/${IMAGE_NAME}:${TAG} | |
docker push ${REGISTRY}/${IMAGE_NAME} |
Thanks!
#!/bin/bash
set -ex
PARENT_DIR=$(basename "${PWD%/*}")
CURRENT_DIR="${PWD##*/}"
IMAGE_NAME="$PARENT_DIR/$CURRENT_DIR"
TAG="${1}"
REGISTRY="hub.docker.com"
docker build -t ${REGISTRY}/${IMAGE_NAME}:${TAG} -t ${REGISTRY}/${IMAGE_NAME}:latest .
docker push ${REGISTRY}/${IMAGE_NAME}
Just summarizing
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very helpful. Thanks!
By the way, you can supply multiple
-t
options to docker build, and save a tag and push.