DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • Container Checkpointing in Kubernetes With a Custom API
  • Leveraging Seekable OCI: AWS Fargate for Containerized Microservices
  • Redefining Artifact Storage: Preparing for Tomorrow's Binary Management Needs
  • Deploying Dockerized Applications on AWS Lambda: A Step-by-Step Guide

Trending

  • How Developers Are Driving Supply Chain Innovation With Modern Tech
  • How My AI Agents Learned to Talk to Each Other With A2A
  • The Battle of the Frameworks: Choosing the Right Tech Stack
  • How to Use AI to Understand Gaps in Your Resume and Job Descriptions
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Highly Available Docker Registry on AWS With Nexus

Highly Available Docker Registry on AWS With Nexus

Want a place to keep your Docker images that won't fail when the chips are down? See how you can create an HA repo on AWS using Nexus.

By 
Mohamed Labouardy user avatar
Mohamed Labouardy
·
Dec. 20, 17 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
11.3K Views

Join the DZone community and get the full member experience.

Join For Free

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

In this post, 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 our IaC (Infrastructure as Code) tool. The advantage of using this kind of tool is the ability to spin up a new environment quickly in a different AWS region (or a different IaaS provider) in case of an incident (disaster recovery).

Start by cloning the following GitHub repository:

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


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

resource "aws_instance" "default" {
  ami             = "${lookup(var.amis, var.region)}"
  instance_type   = "${var.instance_type}"
  key_name        = "${aws_key_pair.default.id}"
  security_groups = ["${aws_security_group.default.name}"]

  user_data = "${file("setup.sh")}"

  tags {
    Name = "registry"
  }
}


I specified a shell script to be used as user_data when launching the instance. It will simply install the latest version of Docker CE and turn the instance to Docker Swarm Mode (to benefit from replication and high availability of the Nexus container)

#!/bin/sh
yum update -y
yum install -y docker
service docker start
usermod -aG docker ec2-user
docker swarm init
docker service create --replicas 1 --name registry --publish 5000:5000 --publish 8081:8081 sonatype/nexus3:3.6.2


Note: You can use Configuration Management Tools like Ansible or Chef to provision the server once created.

Then, issue the following command to create the infrastructure:

terraform apply -var-file=variables.tfvars


Once created, you should see the Elastic IP of your instance:

Connect to your instance via SSH:

ssh [email protected]


Verify that the Docker Engine is running in Swarm Mode:

Check that the Nexus service is running:

Go back to your AWS Management Console, then, navigate to the Route53 Dashboard. You should see that a new A record has been created that points to the instance IP address.

Point your favorite browser to the Nexus Dashboard URL (registry.slowcoder.com:8081). Log in and create a Docker-hosted registry as below:

Edit the /etc/docker/daemon.json file, it should have the following content:

{
    “insecure-registries” : [“registry.slowcoder.com:5000”]
}


Note: For production, it’s highly recommended that you secure your registry using a TLS certificate issued by a known CA.

Restart Docker for the changes to take effect:

service docker restart


Log into your registry with your Nexus credentials (admin/admin123):

In order to push a new image to the registry:

docker push registry.slowcoder.com:5000/mlabouardy/movies-api:1.0.0-beta


Verify that the image has been pushed to the remote repository:

To pull the Docker image:

docker pull registry.slowcoder.com:5000/mlabouardy/movies-api:1.0.0-beta


Note: Sometimes you end up with many unused and dangling images that can quickly take up a significant amount of disk space:

You can either use the Nexus CLI tool or create a Nexus Task to clean up old Docker Images:

Populate the form as below:

The task above will run every day at midnight to purge unused Docker images from the “mlabouardy” registry.

Docker (software) AWS Nexus (standard)

Opinions expressed by DZone contributors are their own.

Related

  • Container Checkpointing in Kubernetes With a Custom API
  • Leveraging Seekable OCI: AWS Fargate for Containerized Microservices
  • Redefining Artifact Storage: Preparing for Tomorrow's Binary Management Needs
  • Deploying Dockerized Applications on AWS Lambda: A Step-by-Step Guide

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: