---
# System prepended metadata

title: Hydra install

---

# Hydra install

## Setup hosts

Host hydra

Host postgress

Vagrantfile
```
# -*- mode: ruby -*-
# vi: set ft=ruby :

boxes = [
    {
        :name => "hydra",
        :eth1 => "192.168.33.12",
        :mem => "1024",
        :cpu => "1"
    },
    {
        :name => "postgresql",
        :eth1 => "192.168.33.13",
        :mem => "1024",
        :cpu => "1"
    }
]

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"

  config.vm.provision "file", source: "~/.ssh/id_rsa.pub", destination: "~/.ssh/me.pub"
  config.vm.provision "shell", inline: <<-SHELL
    cat /home/vagrant/.ssh/me.pub >> /home/vagrant/.ssh/authorized_keys
  SHELL

  boxes.each_with_index do |opts, index|
    config.vm.define opts[:name] do |config|
      config.vm.hostname = opts[:name]

      config.vm.provider "virtualbox" do |vb|
        vb.memory = opts[:mem]
        vb.cpus = opts[:cpu]
      end

      config.vm.network :private_network, ip: opts[:eth1]

    end
  end
end
```

Run via docker

## Install Postgre

```bash
sudo apt update
sudo apt install docker.io -y
```

```bash
sudo docker run --name ory-hydra-postgres -e POSTGRES_USER=hydra -e POSTGRES_PASSWORD=secret -e POSTGRES_DB=hydra -p 5432:5432 -d postgres:9.6
```

## Install Hydra

```bash
sudo apt update
sudo apt install docker.io -y
```

```bash
export SECRETS_SYSTEM=$(export LC_CTYPE=C; cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
```

```bash
export DSN=postgres://hydra:secret@192.168.33.13:5432/hydra?sslmode=disable
```

```bash
sudo docker pull oryd/hydra:v1.10.6
```

```bash
sudo docker run -it --rm oryd/hydra:v1.10.6 migrate sql --yes $DSN
```

```bash
sudo docker run -d --name ory-hydra -p 9000:4444 -p 9001:4445 -e SECRETS_SYSTEM=$SECRETS_SYSTEM -e DSN=$DSN -e URLS_SELF_ISSUER=https://192.168.33.12:9000/ -e URLS_CONSENT=http://192.168.33.12:9020/consent -e URLS_LOGIN=http://192.168.33.12:9020/login oryd/hydra:v1.10.6 serve all
```

## Работа с Гидрой

-p 9000:4444 exposes ORY Hydra's public API on https://localhost:9000/.
-p 9001:4445 exposes ORY Hydra's administrative API on https://localhost:9001/.