Last active
February 27, 2016 18:16
-
-
Save smreed/afc7187fc238efad15fe to your computer and use it in GitHub Desktop.
Shell script that starts up a local docker registry with a Google Cloud Storage backend using local credentials.
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
#!/bin/bash | |
LOCAL_REGISTRY_NAME=local-docker-registry | |
GCS_BUCKET=some-bucket | |
CONFIG_DIR=$HOME/.config | |
LOCAL_REGISTRY_ID=`docker ps -q $LOCAL_REGISTRY_NAME` | |
if [ ! -z "$LOCAL_REGISTRY_ID" ]; then | |
echo "Found ${LOCAL_REGISTRY_ID}, stopping..." | |
docker stop "${LOCAL_REGISTRY_ID}" >/dev/null 2>&1 | |
echo "Removing..." | |
docker rm "${LOCAL_REGISTRY_ID}" >/dev/null 2>&1 | |
fi | |
echo "Starting..." | |
LOCAL_REGISTRY_ID=`docker run -d --name="${LOCAL_REGISTRY_NAME}" -e GCS_BUCKET=$GCS_BUCKET -v "${CONFIG_DIR}:/.config" -p 5000:5000 google/docker-registry` | |
if [ -z "$LOCAL_REGISTRY_ID" ]; then | |
>&2 echo "Could not start ${LOCAL_REGISTRY_NAME}" | |
exit 1 | |
fi | |
echo "Waiting for registry to come online (will wait up to 10 seconds)..." | |
RUNNING="false" | |
for i in `seq 1 10`; do | |
echo "Check #${i}" | |
RUNNING=`curl localhost:5000/v1/_ping 2>/dev/null` | |
if [ "${RUNNING}" = "true" ]; then | |
break | |
fi | |
sleep 1 | |
done | |
if [ "$RUNNING" != "true" ]; then | |
echo "Local registry never came up, aborting" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment