Skip to content

Instantly share code, notes, and snippets.

@Tranquility2
Created May 12, 2024 17:11
Show Gist options
  • Save Tranquility2/20652b77a012ee54ae1c8ca021aea1ff to your computer and use it in GitHub Desktop.
Save Tranquility2/20652b77a012ee54ae1c8ca021aea1ff to your computer and use it in GitHub Desktop.

Setup and testing using local docker registry

Making the credential file

Create the folder

mkdir registry
cd registry/
mkdir auth

Crete the auth file

apt-get install apache2-utils
htpasswd -Bbn test_user  test_password  > auth/htpasswd

Important

Validate using cat auth/htpasswd

Alternatively (Using a dedicated container)

mkdir auth
docker run --entrypoint htpasswd httpd:2 -Bbn test_user test_password > auth/htpasswd

Run the local docker registry

docker run -d \
  -p 5000:5000 \
  --restart=always \
  --name registry \
  -v "$(pwd)"/auth:/auth \
  -e "REGISTRY_AUTH=htpasswd" \
  -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
  -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
  registry:2.7.0

Testing

Create test image

docker pull busybox
docker tag busybox:latest localhost:5000/busybox

Login

docker login localhost:5000 

Or simply docker login -u test_user -p test_password localhost:5000

Test push

docker push localhost:5000/busybox

Note

Credentials are saved in ~/.docker/config.json

Tessting DOCKER_AUTH_CONFIG

Create the env var

export DOCKER_AUTH_CONFIG=`cat ~/.docker/config.json`

Important

Validate using echo "$DOCKER_AUTH_CONFIG"

{
   "auths": {
       "registry.example.com:5000": {
           "auth": "bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ="
       }
   }
}

Tag with local registry

docker tag redis:latest localhost:5000/redis:latest

Push to local registry

docker push localhost:5000/redis:latest

You should now be able to test using localhost:5000/redis:latest


Reference:
https://stackoverflow.com/questions/38247362/how-i-can-use-docker-registry-with-login-password https://stackoverflow.com/questions/62531462/docker-local-registry-exec-htpasswd-executable-file-not-found-in-path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment