# Build a Highly Available Docker Registry on AWS With Sonatype Nexus Repository

**January 04, 2018**  
By Mohamed Labouardy

10 minute read time

Have you ever wondered how you can build a highly available and resilient Docker Repository to store your Docker Images?

In this article, we will setup an EC2 instance inside a Security Group and create an A record pointing to the server Elastic IP address as follows:

To provision the infrastructure, we will use Terraform as IaC (Infrastructure as Code) tool. The advantage of using this kind of tool is the ability to spin up a new environment quickly in different AWS region (or different IaaS providers) in case of incident (disaster recovery).

Start by cloning the following GitHub [repository](/content/resources/articles/what-are-code-repositories/index.html):

|     |     |
| --- | --- |
| 1 | git clone https://github.com/mlabouardy/terraform-aws-labs.git |

Inside _docker-registry_ folder, update the variables.tfvars with your own AWS credentials (make sure you have the right IAM policies).

|     |     |
| --- | --- |
| 1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>10<br>11<br>12 | resource "aws_instance" "default" {<br>ami="${lookup(var.amis, var.region)}"<br>instance_type="${var.instance_type}"<br>key_name="${aws_key_pair.default.id}"<br>security_groups=["${aws_security_group.default.name}"]<br>user_data="${file("setup.sh")}\
