2015-06-08 00:58:53 +00:00
<!-- [metadata]>
+++
title = "Deploying a registry server"
description = "Explains how to deploy a registry server"
keywords = ["registry, service, images, repository"]
[menu.main]
parent="smn_registry"
2015-06-16 13:00:24 +00:00
weight=3
2015-06-08 00:58:53 +00:00
+++
<![end-metadata]-->
2015-04-29 19:20:09 +00:00
2015-04-19 00:06:51 +00:00
# Deploying a registry server
2015-04-03 18:12:34 +00:00
2015-06-01 03:09:15 +00:00
You obviously need to [install Docker ](https://docs.docker.com/installation/ ) (remember you need **Docker version 1.6.0 or newer** ).
2015-05-22 09:14:55 +00:00
2015-06-11 04:05:13 +00:00
## Getting started
2015-05-22 09:14:55 +00:00
Start your registry:
2015-05-22 09:46:23 +00:00
$ docker run -d -p 5000:5000 \
--restart=always --name registry registry:2
2015-05-22 09:14:55 +00:00
That's it.
You can now tag an image and push it:
2015-06-01 03:09:15 +00:00
$ docker pull ubuntu & & docker tag ubuntu localhost:5000/batman/ubuntu
2015-05-22 09:14:55 +00:00
$ docker push localhost:5000/batman/ubuntu
2015-06-01 03:09:15 +00:00
Then pull it back:
2015-05-22 09:14:55 +00:00
$ docker pull localhost:5000/batman/ubuntu
2015-06-11 04:05:13 +00:00
## Where is my data?
By default, your registry stores its data on the local filesystem, inside the container.
2015-06-18 01:58:53 +00:00
In a production environment, it's highly recommended to use [another storage backend ](storagedrivers.md ), by [configuring it ](configuration.md ).
2015-06-11 04:05:13 +00:00
If you want to stick with the local posix filesystem, you should store your data outside of the container.
This is achieved by mounting a volume into the container:
$ docker run -d -p 5000:5000 \
-e REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/var/lib/registry \
-v /myregistrydata:/var/lib/registry \
--restart=always --name registry registry:2
2015-05-22 09:14:55 +00:00
## Making your Registry available
2015-06-01 03:09:15 +00:00
Now that your registry works on `localhost` , you probably want to make it available as well to other hosts.
2015-05-22 09:14:55 +00:00
Let assume your registry is accessible via the domain name `myregistrydomain.com` (still on port `5000` ).
If you try to `docker pull myregistrydomain.com:5000/batman/ubuntu` , you will see the following error message:
```
2015-06-11 04:05:13 +00:00
FATA[0000] Error response from daemon: v1 ping attempt failed with error:
Get https://myregistrydomain.com:5000/v1/_ping: tls: oversized record received with length 20527.
If this private registry supports only HTTP or HTTPS with an unknown CA certificate,please add
`--insecure-registry myregistrydomain.com:5000` to the daemon's arguments.
In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag;
simply place the CA certificate at /etc/docker/certs.d/myregistrydomain.com:5000/ca.crt
2015-05-22 09:14:55 +00:00
```
2015-06-01 03:09:15 +00:00
If trying to reach a non `localhost` registry, Docker requires that you secure it using https, or make it explicit that you want to run an insecure registry.
You basically have three different options to comply with that security requirement here.
2015-05-22 09:14:55 +00:00
### 1. buy a SSL certificate for your domain
This is the (highly) recommended solution.
You can buy a certificate for as cheap as 10$ a year (some registrars even offer certificates for free), and this will save you a lot of trouble.
Assuming you now have a `domain.crt` and `domain.key` inside a directory named `certs` :
```
# Stop your registry
docker stop registry & & docker rm registry
# Start your registry with TLS enabled
docker run -d -p 5000:5000 \
-v `pwd` /certs:/certs \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \
-e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \
--restart=always --name registry \
registry:2
```
2015-07-10 21:10:25 +00:00
A certificate issuer may supply you with an *intermediate* certificate. In this case, you must combine your certificate with the intermediate's to form a *certificate bundle* . You can do this using the `cat` command:
```
$ cat server.crt intermediate-certificates.pem > server.with-intermediate.crt
```
You then configure the registry to use your certificate bundle by providing the `REGISTRY_HTTP_TLS_CERTIFICATE` environment variable.
2015-07-09 22:28:08 +00:00
2015-05-22 09:14:55 +00:00
**Pros:**
- best solution
- work without further ado (assuming you bought your certificate from a CA that is trusted by your operating system)
**Cons:**
- ?
### 2. instruct docker to trust your registry as insecure
This basically tells Docker to entirely disregard security for your registry.
2015-06-01 03:09:15 +00:00
1. edit the file `/etc/default/docker` so that there is a line that reads: `DOCKER_OPTS="--insecure-registry myregistrydomain.com:5000"` (or add that to existing `DOCKER_OPTS` ). Restart docker.
2015-05-22 09:14:55 +00:00
2. restart your Docker daemon: on ubuntu, this is usually `service docker stop && service docker start`
**Pros:**
- easy to configure
**Cons:**
- very insecure
- you have to configure every docker daemon that wants to access your registry
2015-04-02 15:11:19 +00:00
2015-05-22 09:14:55 +00:00
### 3. use a self-signed certificate and configure docker to trust it
Alternatively, you can generate your own certificate:
```
mkdir -p certs & & openssl req \
-newkey rsa:4096 -nodes -sha256 -keyout certs/domain.key \
-x509 -days 365 -out certs/domain.crt
```
Be sure to use the name `myregistrydomain.com` as a CN.
Now go to solution 1 above and stop and restart your registry.
2015-06-01 03:09:15 +00:00
Then you have to instruct every docker daemon to trust that certificate. This is done by copying the `domain.crt` file to `/etc/docker/certs.d/myregistrydomain.com:5000/ca.crt` (don't forget to restart docker after doing so).
2015-05-22 09:14:55 +00:00
**Pros:**
- more secure than solution 2
**Cons:**
- you have to configure every docker daemon that wants to access your registry
## Using Compose
2015-06-08 22:54:46 +00:00
It's highly recommended to use [Docker Compose ](https://docs.docker.com/compose/ ) to facilitate managing your Registry configuration.
2015-05-22 09:14:55 +00:00
Here is a simple `docker-compose.yml` that does setup your registry exactly as above, with TLS enabled.
```
registry:
restart: always
image: registry:2
ports:
- 5000:5000
environment:
REGISTRY_HTTP_TLS_CERTIFICATE: /certs/domain.crt
REGISTRY_HTTP_TLS_KEY: /certs/domain.key
2015-06-11 04:05:13 +00:00
REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /var/lib/registry
2015-05-22 09:14:55 +00:00
volumes:
2015-06-11 04:05:13 +00:00
- /path/registry-data:/var/lib/registry
2015-05-22 09:46:23 +00:00
- /path/certs:/certs
2015-04-02 15:11:19 +00:00
```
2015-05-22 09:14:55 +00:00
You can then start your registry with a simple
$ docker-compose up -d
## Next
2015-04-10 22:16:13 +00:00
2015-05-22 09:14:55 +00:00
You are now ready to explore [the registry configuration ](configuration.md )