First version with user/password auth

This commit is contained in:
2024-06-10 18:42:44 +02:00
parent 6d55c95479
commit 9ecf2e931d
5 changed files with 173 additions and 1 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
auth/htpasswd

View File

@ -1,3 +1,67 @@
# dockerRegistry
A container image repository using docker.
A container image repository using docker.
## How to use
```shell
./registry.sh
usage: ./registry.sh options
Quickly manage a simple docker registry.
OPTIONS:
c Create user config
s Start registry
d Stop registry
h Show help
```
### Create user/password
```shell
./registry.sh c
Set User name and press enter:testuser
Set Password and press enter:password
Name: testuser
Password: password. Is this correct? (y/n)y
User testuser added to auth/passwd
```
### Start registry
You must create a user/password first.
```shell
./registry.sh s
[+] Running 1/1
✔ Container dockerRegistry Started
```
### Stop registry
```shell
./registry.sh d
[+] Stopping 1/1
✔ Container dockerRegistry Stopped
```
### Connect to the registry
Example assuming that the IP of the machine where the container is running is 192.168.10.50
```shell
docker login -u testuser -p password 192.168.10.25:5010
```
### Upload an image to the registry
```shell
docker tag hello-word 192.168.10.25:5010/hello-world:latest
docker push 192.168.10.25:5010/hello-world:latest
```
### Pulling an image from the registry
```shell
docker pull 192.168.10.25:5010/hello-world:latest
```

25
docker-compose.yaml Normal file
View File

@ -0,0 +1,25 @@
version: "3"
services:
registry:
restart: on-failure
image: registry:2
container_name: dockerRegistry
ports:
- 5010:5000
environment:
- REGISTRY_AUTH=htpasswd
- REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm"
- REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd
# - REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/data
# - REGISTRY_AUTH=token
# - REGISTRY_AUTH_TOKEN_REALM=https://localhost:5011/auth
# - REGISTRY_AUTH_TOKEN_SERVICE=Authentication
# - REGISTRY_AUTH_TOKEN_ISSUER=Example Issuer
# - REGISTRY_AUTH_TOKEN_ROOTCERTBUNDLE=/mnt/local/certs/RootCA.crt
# - REGISTRY_HTTP_TLS_CERTIFICATE=/mnt/local/certs/RootCA.crt
# - REGISTRY_HTTP_TLS_KEY=/mnt/local/certs/RootCA.key
volumes:
- ./auth:/auth
# - ".data/auth/registry/data:/mnt/registry/data"
# - "./registry-auth/certs:/mnt/local/certs"

45
registry.sh Executable file
View File

@ -0,0 +1,45 @@
#!/bin/bash
OPTION=$1
# Functions
usage()
{
cat << EOF
usage: $0 options
Quickly manage a simple docker registry.
OPTIONS:
c Create user config
s Start registry
d Stop registry
h Show help
EOF
}
genUser()
{
"$PWD"/scripts/gen_user.sh
}
startContainer()
{
docker compose up -d
}
stopContainer()
{
docker compose stop
}
case "$OPTION"
in
h)
usage
exit 0
;;
c) genUser;;
s) startContainer;;
d) stopContainer;;
*)
usage
exit 1
;;
esac

37
scripts/gen_user.sh Executable file
View File

@ -0,0 +1,37 @@
#!/bin/bash
aksUser()
{
read -p "Set User name and press enter:" USER_NAME
}
askPassword()
{
read -p "Set Password and press enter:" USER_PASSWORD
}
askConfirm()
{
echo "Name: $USER_NAME"
read -p "Password: $USER_PASSWORD. Is this correct? (y/n)" CONFIRM
}
setPassword()
{
docker run --entrypoint htpasswd httpd:2 -Bbn $USER_NAME $USER_PASSWORD > auth/htpasswd
}
aksUser;
askPassword;
clear;
askConfirm;
while true; do
case $CONFIRM in
[Yy]* ) clear;setPassword; echo "User ${USER_NAME} added to auth/passwd"; break;;
[Nn]* ) askPassword;askConfirm;;
* ) echo "Please, asnwer with y/n."; askPassword;askConfirm;;
esac
done