-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-push.sh
54 lines (45 loc) · 1.53 KB
/
docker-push.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh
# =======================================================================================
# Push image in Docker Hub
#
# This script runs a login to Docker Hub, adds a tag to the local image, and pushes the
# image online
# =======================================================================================
# ------------------------------------------------------
# Common parameters
export IMAGE_NAME=arm-nginx
if [[ ! $1 ]] || [[ "$1" = "h" ]] || [[ "$1" = "help" ]] || [[ "$1" = "-h" ]] || [[ "$1" = "-help" ]] || [[ "$1" = "--h" ]] || [[ "$1" = "--help" ]]; then
echo 'Push a Docker image to Docker Hub (with login and tagging).'
echo ''
echo 'Usage:'
echo ' docker-push.sh DOCKER_HUB_USERNAME [IMAGE_NAME]'
echo ' docker-push.sh h | help | -h | -help | --h | --help'
echo ''
echo 'Options:'
echo " DOCKER_HUB_USERNAME Login for Docker Hub"
echo " IMAGE_NAME Name of the image [default: ${IMAGE_NAME}]"
echo ''
exit 1
fi
DOCKER_ID_USER=$1
if [[ $2 ]]; then
IMAGE_NAME=$2
else
echo "Using default image name: ${IMAGE_NAME}"
fi
# ------------------------------------------------------
# Commands
echo "Login to Docker Hub as user: ${DOCKER_ID_USER}"
docker login -u=${DOCKER_ID_USER}
RESULT=$?
if [[ ${RESULT} != 0 ]] ; then
exit 1
fi
echo "Tag image: ${IMAGE_NAME}"
docker tag -f ${IMAGE_NAME} ${DOCKER_ID_USER}/${IMAGE_NAME}
RESULT=$?
if [[ ${RESULT} != 0 ]] ; then
exit 1
fi
echo "Push image to: ${DOCKER_ID_USER}/${IMAGE_NAME}"
docker push ${DOCKER_ID_USER}/${IMAGE_NAME}