Support for docker registry
diff --git a/README.rst b/README.rst
index 002694c..111fa88 100644
--- a/README.rst
+++ b/README.rst
@@ -52,10 +52,44 @@
             ports:
               - "5432:5432"
 
+Registry
+--------
+
+.. code-block:: yaml
+
+    docker:
+      registry:
+        log:
+          level: debug
+          formatter: json
+        cache:
+          engine: redis
+          host: localhost
+        storage:
+          engine: filesystem
+          root: /srv/docker/registry
+        bind:
+          host: 0.0.0.0
+          port: 5000
+        hook:
+          mail:
+            levels:
+              - panic
+            # Options are rendered as yaml as is so use hook-specific options here
+            options:
+              smtp:
+                addr: smtp.sendhost.com:25
+                username: sendername
+                password: password
+                insecure: true
+              from: name@sendhost.com
+              to:
+                - name@receivehost.com
+
 
 Read more
 ---------
 
 * https://docs.docker.com/installation/ubuntulinux/
 * https://github.com/saltstack-formulas/docker-formula
- 
\ No newline at end of file
+
diff --git a/docker/files/registry.yml b/docker/files/registry.yml
new file mode 100644
index 0000000..734e75a
--- /dev/null
+++ b/docker/files/registry.yml
@@ -0,0 +1,49 @@
+{%- from "docker/map.jinja" import registry with context -%}
+version: 0.1
+log:
+  level: {{ registry.log.level|default('info') }}
+  formatter: {{ registry.log.formatter|default('text') }}
+  fields:
+    service: registry
+storage:
+  cache:
+    blobdescriptor: {{ registry.cache.engine }}
+  {%- if registry.storage.engine == 'filesystem' %}
+  filesystem:
+    rootdirectory: {{ registry.storage.root }}
+  {%- endif %}
+{%- if registry.cache.engine == redis %}
+redis:
+  addr: {{ registry.cache.get('host', 'localhost') }}:{{ registry.cache.get('port', 6379) }}
+  {%- if registry.cache.password is defined %}
+  password: {{ registry.cache.password }}
+  {%- endif %}
+  {%- if registry.cache.db is defined %}
+  password: {{ registry.cache.db }}
+  {%- endif %}
+{%- endif %}
+http:
+  addr: {{ registry.bind.host }}:{{ registry.bind.port }}
+  {%- if registry.secret is defined %}
+  secret: {{ registry.secret }}
+  {%- endif %}
+  headers:
+    X-Content-Type-Options: [nosniff]
+health:
+  storagedriver:
+    enabled: true
+    interval: 10s
+    threshold: 3
+{%- if registry.hook is defined %}
+hooks:
+  {%- for type, hook in registry.hooks %}
+  - type: {{ type }}
+    levels:
+      {%- for level in hook.levels %}
+      - {{ level }}
+      {%- endfor %}
+    {%- if hook.options is defined %}
+    options: {{ hook.options|yaml }}
+    {%- endif %}
+  {%- endfor %}
+{%- endif %}
diff --git a/docker/init.sls b/docker/init.sls
index 410a782..eb9dcb5 100644
--- a/docker/init.sls
+++ b/docker/init.sls
@@ -9,4 +9,7 @@
 {%- if pillar.docker.compose is defined %}
 - docker.compose
 {%- endif %}
-{%- endif %}
\ No newline at end of file
+{%- if pillar.docker.registry is defined %}
+- docker.registry
+{%- endif %}
+{%- endif %}
diff --git a/docker/map.jinja b/docker/map.jinja
index 9511e0f..fc83e8b 100644
--- a/docker/map.jinja
+++ b/docker/map.jinja
@@ -43,4 +43,22 @@
         'pkgs': ['docker-engine'],
         'service': 'docker'
     },
-}, grain='os', merge=salt['pillar.get']('docker:compose')) %}
\ No newline at end of file
+}, grain='os', merge=salt['pillar.get']('docker:compose')) %}
+
+{% set registry = salt['grains.filter_by']({
+    'Debian': {
+        'pkgs': ['docker-registry'],
+        'service': 'docker-registry',
+        'cache': {
+            'engine': 'inmemory',
+        },
+        'storage': {
+            'engine': 'filesystem',
+            'root': '/var/lib/docker-registry',
+        },
+        'bind': {
+            'host': '0.0.0.0',
+            'port': 5000,
+        },
+    },
+}, grain='os', merge=salt['pillar.get']('docker:registry')) %}
diff --git a/docker/registry.sls b/docker/registry.sls
new file mode 100644
index 0000000..3611f6a
--- /dev/null
+++ b/docker/registry.sls
@@ -0,0 +1,34 @@
+{%- from "docker/map.jinja" import registry with context -%}
+{%- if registry.get('enabled', True) %}
+
+docker_registry_packages:
+  pkg.installed:
+    - pkgs: {{ registry.pkgs }}
+    - watch_in:
+      - service: docker_registry_service
+
+docker_registry_service:
+  service.running:
+    - name: {{ registry.service }}
+    - require:
+      - pkg: docker_registry_packages
+
+docker_registry_config:
+  file.managed:
+    - source: salt://docker/files/registry.yml
+    - template: jinja
+    - require:
+      - pkg: docker_registry_packages
+    - watch_in:
+      - service: docker_registry_service
+
+{%- if registry.storage.engine == 'filesystem' %}
+docker_registry_storage_root:
+  file.directory:
+    - name: {{ registry.storage.root }}
+    - owner: docker-registry
+    - group: docker-registry
+    - mode: 750
+{%- endif %}
+
+{%- endif %}
diff --git a/metadata/service/registry.yml b/metadata/service/registry.yml
new file mode 100644
index 0000000..80357fc
--- /dev/null
+++ b/metadata/service/registry.yml
@@ -0,0 +1,6 @@
+applications:
+- docker
+parameters:
+  docker:
+    registry:
+      enabled: true