Search code examples
dockerraspberry-piregistrydocker-swarm

Docker Registry Image - Persistence


I have created docker private registry and able to push and pull from other raspi in the same network( added the registry ip to insecure-registry option)

docker push registry-ip:5000/image

but when my registry server machine is restarted, I am not able to see the repository image and I need to again push the image to the registry host machine:

curl -v registry-server-ip:5000/v2/_catalog

returns nothing

Why it is so? It should be persistent and should retain the image in the registry as it stores in docker images

Any workaround or any configuration that can handle the situation

================UPDATE============================

Docker-Compose.yml

version: '3.4'
services:
  service1:
    image: ${REGISTRY_SERVER_IP}:5000/service1
    build: .
    restart: always
    deploy:
      mode: global
      restart_policy:
        condition: on-failure
      ports: 
        - 3632:3632
      entrypoint: 
        - init.sh

init.sh is just script to run some server
Dockerfile has base image with some apt-get install update commands

I am running this script:

  1. Creating Registry Server

docker service create --name registry --publish published=5000,target=5000 registry:2 --> This will create registry server in the same machine

  1. Running docker-compose build --> build the image locally with the docker file

  2. docker-compose push --> Push to Registry Server as in docker compose

Now when I am restarting the machine, the container/service is automatically triggered but the image in the repo is lost.


Solution

  • You have to mount a volume in order to persist your data, you can do this with the volume option as mentioned in the docs. By applying this your image would become something like this:

    version: '3.4'
    services:
      service1:
        image: ${REGISTRY_SERVER_IP}:5000/service1
        build: .
        restart: always
        deploy:
          mode: global
          restart_policy:
            condition: on-failure
        ports: 
          - 3632:3632
        volumes:
          - /path/to/local:/var/lib/registry
        entrypoint: 
          - init.sh
    

    Note: change the part before the : to your local path where you want to persist the data or use a named volume