Skip to content

Instantly share code, notes, and snippets.

@motaharinia
Last active January 2, 2022 19:39
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 motaharinia/5a7ee1cb1815bb3804327bd15f762bc3 to your computer and use it in GitHub Desktop.
Save motaharinia/5a7ee1cb1815bb3804327bd15f762bc3 to your computer and use it in GitHub Desktop.
docker-registry
1[a].run in cmd (install httpd on windows to use for registry authentication. --entrypoint : default command to execute at runtime.):
docker run --rm --entrypoint htpasswd httpd:2 -Bbn testuser testpassword | Set-Content -Encoding ASCII D:\work\services\dockerimagelocation\dockerregistry\auth\htpasswd
1[b].install from https://htpasswdgenerator.com/download_htpasswd_generator.html and use htpasswd.exe with:
htpasswd -cbd testuser testpassword D:\work\services\dockerimagelocation\dockerregistry\auth\htpasswd
1[c].create it online with https://wtools.io/generate-htpasswd-online or https://hostingcanada.org/htpasswd-generator/ and put it to a htpasswd file:
-mkdir -p D:\work\services\dockerimagelocation\dockerregistry\auth
echo testuser:$2y$10$u3qOwd1erQ4QBnj/jtARseiLiF1HU6Rz00cBa7nDbxzlXMUKzKPyW > D:\work\services\dockerimagelocation\dockerregistry\auth\htpasswd
2.domain and cert config for 443 (https):
-mkdir -p D:\work\services\dockerimagelocation\dockerregistry\certs
-add sample record in C:\Windows\System32\drivers\etc\hosts:
127.0.0.1 dockerreg.local
-create self signed certificate on https://www.selfsignedcertificate.com with domain "dockerreg.local" and downlaod and rename files to dockerreg.local.cert and dockerreg.local.key
-copy dockerreg.local.cert and dockerreg.local.key files into the D:\work\services\dockerimagelocation\dockerregistry\certs directory
-edit the daemon.json file, which is located in /etc/docker/ on Linux hosts and C:\ProgramData\docker\config\daemon.json on Windows Server. Assuming the file was previously empty, add the following contents:
{
"allow-nondistributable-artifacts": ["dockerreg.local:5000"]
}
3.run in cmd (install docker registry):
docker run -d --name mydockerregistry --restart unless-stopped -p 5000:5000 --network=host -e TZ=Asia/Tehran -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/dockerreg.local.cert -e REGISTRY_HTTP_TLS_KEY=/certs/dockerreg.local.key -e REGISTRY_AUTH=htpasswd -e REGISTRY_AUTH_HTPASSWD_REALM=RegistryRealm -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd -v D:\work\services\dockerimagelocation\dockerregistry\auth:/auth -v D:\work\services\dockerimagelocation\dockerregistry\certs:/certs -v D:\work\services\dockerimagelocation\dockerregistry\registry:/var/lib/registry registry:2
4.Login to docker registry with testuser and testpassword:
docker login -u testuser -p testpassword dockerreg.local:5000
docker images
5.List all repositories (effectively images):
curl -X GET -u testuser:testpassword https://dockerreg.local:5000/v2/_catalog
links:
https://hub.docker.com/_/registry
https://docs.docker.com/registry/
https://gabrieltanner.org/blog/docker-registry
https://docs.docker.com/registry/deploying/#restricting-access
https://docs.docker.com/engine/reference/commandline/login/
https://docs.docker.com/engine/reference/commandline/build/
https://docs.docker.com/engine/reference/commandline/push/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment