• 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Setup trusted Docker registry on a Raspberry Pi to host netPI containers
#1
How to setup an own trusted Docker Registry Server (comes as a container from Docker Hub) to push and pull Docker images to and from.

As example a standard Raspberry Pi (RPi) preloaded with Raspbian OS is used but you can be any Linux Host:

Make a basic setup of your RPi:

  1. Get terminal access to the system using a tool like putty
  2. Change to user root
    $ sudo -i
  3. Install Docker Engine
    $ curl -sSL https://get.docker.com | sh
  4. Give your RPi a reasonable Hostname e.g. myregistry. (The name has to be lowercase since Docker can address image/tags/registries by name only if they are lowercase. A discrete Hostname is necessary since it is strongly recommended that trusted CA certificates identifiying a device as secure should not be issued for the device's IP address but for its Hostname instead.) Use an editor (e.g.nano) to change the current Hostname raspberrypi to myregistry in the two files:
    $ nano /etc/hosts (string behind the ip address 127.0.1.1)
    $ nano /etc/hostname

  5. (optional) If you want to make the Hostname public in a MS Windows based office network you have to install two additional services
    $ apt-get install samba
    $ apt-get install winbind

    Additionally the wins service needs to be activated. Edit the following file in an editor
    $ nano /etc/nsswitch.conf[/b]
    In the line hosts: add the term wins and mdns4 to the existing terms files, dns, mdns4_minimal and others
  6. Reboot the system
    $ reboot now
  7. After the reboot generate new SSH keys pairs. First remove old ones
    $ rm /etc/ssh/ssh_host_*
  8. Reconfigure SSH server and generate new key pairs
    $ dpkg-reconfigure openssh-server
  9. Restart SSH server
    $ service ssh restart
Generate a self signed certificate with help of an own CA(Certificate Authority):

  1. Create a folder certs on your RPi host and move to it. This folder is mapped later into the Registry Server container using the Docker "volume mapping" parameter allowing to mirror a host folder in a container when it is started. So this folder serves as storage for the needed keys and certicates for the container.
    $ mkdir -p /certs && cd /certs
  2. Generate a new key devdockerCA.key needed for your own "trusted" CA used as private key.
    $ openssl genrsa -out devdockerCA.key 2048
  3. Generate public certificate of your CA devdockerCA.pem derived from the private key. Adjust the following sample configuration "/C=DE/ST=Hessen ..." to your personal credentials. The devdockerCA.pem file made known on your RPi host lets it accept certificates signed by this CA, respectively the one reported by your Registry Server later.
    $ openssl req -x509 -new -nodes -key devdockerCA.key -days 10000 -out devdockerCA.pem -subj "/C=DE/ST=Hessen/L=Hattersheim/O=Hilscher/OU=Hilscher/CN=myownca/emailAddress=myownca@hilscher.com"
  4. For your Registry Server another key named domain.key needs to be generated that is used as public key and needs later to be signed by your CA.
    $ openssl genrsa -out domain.key 2048
  5. Create a configuration file req.conf with
    $ nano /certs/req.conf
    that necessary for a proper signing procedure. Copy the following content to it and tailored it to your credentials. Especially the CN parameter Common Name has to match your choosen RPi Hostname):
    [ req ]
    distinguished_name = req_distinguished_name
    req_extensions = v3_req
    prompt = no
    [ req_distinguished_name ]
    C = DE
    ST = Hessen
    L = Hattersheim
    O = Hilscher
    OU = netIOT
    CN = myregistry
    emailAddress = mypi@hilscher.com
    [ v3_req ]
    keyUsage = keyEncipherment, dataEncipherment
    extendedKeyUsage = serverAuth
    subjectAltName = @alt_names
    [ req_ext ]
    subjectAltName = @alt_names
    [ alt_names ]
    DNS.1 = myregistry
    DNS.2 = myregistry.local
    DNS.3 = myregistry.domain
    IP.1 = 127.0.0.1

  6. Generate now a CSR (Certificate Signing Request) including the public Registry Server key intended to be signed by your CA.
    $ openssl req -new -key domain.key -out dev-docker-registry.com.csr -config req.conf
  7. Cross sign your Registry Server public key with the private CA merged with the CSR parameters and generate domain.crt file which is the final signed certificate of your Registry Server.
    $ openssl x509 -req -in dev-docker-registry.com.csr -CA devdockerCA.pem -CAkey devdockerCA.key -CAcreateserial -out domain.crt -days 10000 -extensions req_ext -extfile req.conf
  8. Let the public CA certificate become known on your RPi (else pushing to the Registry Server from the local RPi itself (later topic) will fail).
    $ cp /certs/devdockerCA.pem /usr/local/share/ca-certificates/devdockerCA.crt
    $ update-ca-certificates
    $ reboot now

  9. Start the Registry as a container (certs folder is mapped to it)
    $ docker run -d --restart=always --name registry -v /certs:/certs -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key -p 443:5000 registry:2
  10. Check if the Registry Server is running
    $ curl https://myregistry.local/v2/_catalog
    {"repositories":[]} -> returns empty list of repositories, which is fine.
Load a test image on your Registry:

  1. Pull a valid image from the Docker Hub internet registry on your RPi
    $ docker pull nginx:latest

  2. Tag the image with a name fitting to the name of your registry to prepare it for a push
    $ docker tag nginx:latest  myregistry.local/mytest:latest

  3. Push the tagged image to your registry
    $ docker push myregistry.local/mytest:latest

Make the certificate known on your netPI:

  1. Copy the previously created /certs/devdockerCA.pem file from your RPi to a location where it can be uploaded over netPI's Web-GUI.Typically you would use an FTP client such as WinSCP to copy it to your PC/machine running the web browser.
  2. Upload the pem file to your netPI using the Security/Public Key Infrastructure menu, highlighting then Trusted Certification Authorities and clicking upload finally as the picture shows:
       
  3. Reboot the netPI to let the new trusted CA become known on your netPI
Have a look on this video tutorial on Youtube:

https://youtu.be/0QRo3nAkUfo
You never fail until you stop trying.“, Albert Einstein (1879 - 1955)

  Reply


Messages In This Thread
Setup trusted Docker registry on a Raspberry Pi to host netPI containers - by Armin@netPI - July-18th-2018, 09:02 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  https certificate issues in new nodered docker image Dipro 1 1,727 May-4th-2022, 05:46 AM
Last Post: Armin@netPI
  Portainer Stack fails to pull from private Registry Andi 5 5,586 February-16th-2022, 09:03 AM
Last Post: Armin@netPI
  Initial Setup of Control Panel with admin + admin thorws error Michi 4 2,850 January-28th-2022, 09:28 AM
Last Post: Michi
  Docker exposed port don't send data on eth0 COswald 3 3,214 July-15th-2021, 02:10 PM
Last Post: Armin@netPI
  Docker not enabled tad 10 5,007 July-14th-2021, 08:54 AM
Last Post: Armin@netPI
  netPI setup procedure tad 1 2,139 March-15th-2021, 05:48 AM
Last Post: Armin@netPI
  Docker amd64 instead of arm biancode 3 3,130 January-17th-2021, 09:40 PM
Last Post: Armin@netPI
  docker.service start failed EUROKEY 13 9,473 January-17th-2021, 07:52 PM
Last Post: Armin@netPI
  Get host MAC via REST API inside container bschandra 4 3,758 November-16th-2020, 09:26 AM
Last Post: bschandra
  netpi raspberry Hochschulstudent 1 2,378 August-12th-2020, 01:50 PM
Last Post: Armin@netPI

Forum Jump:


Users browsing this thread: 2 Guest(s)