kcl-lang.io/kpm@v0.8.7-0.20240520061008-9fc4c5efc8c7/scripts/reg.sh (about) 1 #!/bin/bash 2 3 # create a directory to store user passwords 4 mkdir -p ./scripts/registry_auth 5 6 # use htpasswd to create an encrypted file 7 htpasswd -Bbn test 1234 > ./scripts/registry_auth/htpasswd 8 9 # check if there is a container named registry 10 if [ "$(docker ps -aq -f name=registry)" ]; then 11 # stop and remove the container named registry 12 docker stop registry 13 docker rm registry 14 fi 15 16 # start the Docker Registry with authentication 17 docker run -p 5001:5000 \ 18 --restart=always \ 19 --name registry \ 20 -v /var/lib/registry:/var/lib/registry \ 21 -v $PWD/scripts/registry_auth/:/auth/ \ 22 -e "REGISTRY_AUTH=htpasswd" \ 23 -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \ 24 -e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" \ 25 -d registry 26 27 # clean the registry 28 docker exec registry rm -rf /var/lib/registry/docker/registry/v2/repositories/