Skip to content

Instantly share code, notes, and snippets.

@didip
Last active June 24, 2024 20:36
Show Gist options
  • Save didip/ff5088fd023624aba7c0 to your computer and use it in GitHub Desktop.
Save didip/ff5088fd023624aba7c0 to your computer and use it in GitHub Desktop.
Small helper script that automates Docker building and pushing
#!/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}
@StevenACoffman
Copy link

StevenACoffman commented Sep 20, 2017

Very helpful. Thanks!
By the way, you can supply multiple -t options to docker build, and save a tag and push.

docker build -t ${REGISTRY}/${IMAGE_NAME}:${TAG} -t ${REGISTRY}/${IMAGE_NAME}:latest .
docker push ${REGISTRY}/${IMAGE_NAME}

@hlogeon
Copy link

hlogeon commented Oct 24, 2017

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