Deploying a registry server on a local instance/server. This example demonstrates native basic auth and using TLS or similar to webserver with SSL.
"auth" is to store credentials. "certs" is for certificates using TLS and "data" is for storing images on registry.
-./root
-./auth
-./certs
-./data
-
Get a certificate
-
Create a certificate directory. Make sure to use the correct name as a CN. Eg: localhost or myregistrydomain.com
mkdir -p certs openssl req -newkey rsa:4096 -nodes -sha256 -keyout certs/domain.key -x509 -days 365 -out certs/domain.crt
-
Copy the
domain.crt
file to/etc/docker/certs.d/myregistrydomain.com:5000/ca.crt
on every Docker host. In this example directorycerts
.
-
-
Basic Authentication
- Create a auth directory and generate a user "testuser" with password "testpassword".
mkdir auth docker run --entrypoint htpasswd registry:2 -Bbn testuser testpassword > auth/htpasswd
- In order to add more users.
docker run --entrypoint htpasswd registry:2 -Bbn testuser2 testpassword2 >> auth/htpasswd
- Create a auth directory and generate a user "testuser" with password "testpassword".
-
Run docker registry
- Pull dokcker registry2 image
docker pull registry:2
- Using docker run
docker run -d -p 6000: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 \ -v `pwd`/certs:/certs \ -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \ -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \ registry:2
- Using docker compose
Note: Replace volumes
registry: restart: always image: registry:2 ports: - 6000:5000 environment: REGISTRY_HTTP_TLS_CERTIFICATE: /certs/domain.crt REGISTRY_HTTP_TLS_KEY: /certs/domain.key REGISTRY_AUTH: htpasswd REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm volumes: - ./data:/var/lib/registry - ./certs:/certs - ./auth:/auth
.\data .\certs .\auth
with your own local directory.
- Pull dokcker registry2 image
-
Using local registry
- Login. Enter credentials "testuser" and password "testpassword"
docker login localhost:6000
- Access local registry
docker pull node docker tag node localhost:6000/node docker push localhost:6000/node docker pull localhost:6000/node
- Logout from local registry
docker Logout localhost:6000
- Similarly you can login using different credentials via
docker login
command.
- Login. Enter credentials "testuser" and password "testpassword"
- Deploying a registry server:
- Test an insecure registry: -
- Building private Docker registry with basic authentication by self-signed certificate, using it from OSX: