Skip to content

Instantly share code, notes, and snippets.

@stampycode
Created June 23, 2017 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stampycode/74cf50dbd48b3857906ada6ed3385676 to your computer and use it in GitHub Desktop.
Save stampycode/74cf50dbd48b3857906ada6ed3385676 to your computer and use it in GitHub Desktop.
Connect to Docker Registry and Fetch an Image without hard-coding credentials
#!/bin/bash
if [[ ! -f bin/docker-credential-registrycreds ]] ; then
[[ ! -d bin ]] && mkdir bin
cat > bin/docker-credential-registrycreds <<FFF
cat <<JSON
{
"ServerURL": "https://registry.local/v1",
"Username": "${DOCKER_USER}",
"Secret": "${DOCKER_PASS}"
}
JSON
FFF
chmod u+x bin/docker-credential-registrycreds
fi
if [[ ! -f .docker/config ]] ; then
[[ ! -d .docker ]] && mkdir .docker
cat > .docker/config.json <<FFF
{
"credsStore": "registrycreds"
}
FFF
fi
read -p "docker registry username: " DOCKER_USER
read -p "docker registry password: " -s DOCKER_PASS
export DOCKER_USER
export DOCKER_PASS
export PATH=$PATH:/root/bin/
docker pull registry.local/your/path/to/repo:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment