What is Docker Registry?

  • The Docker Registry is the backbone of this pipeline.
  • Stores all image versions (tags), enables rollbacks, and facilitates environment-specific deployments using the exact same artifact.
  • It can be run on a local server or on a rented server
  • Some tools that can be used to run the docker registry  are Nexus; however for our example, we will use the Amazon Elastic Container Registry
  • Docker Trusted Registry Can also be Used

Dependencies and Libraries

  • Rebuilding Docker image can be challenging if it contains libraries and dependencies
  • Store independent copies of all dependencies and libraries using docker build images

Building Docker Images

  • Use Git Hashes as Docker image tags
  • Build all Docker Images from Dockerfile and check them on Git
  • Multiple Tags can be used for the same image
  • Automate early and automate often
  • Avoid dependencies and tie a container to a specific host (such as Docker links or shared volumes)
  • Carefully avoid hand-building images
  • Compromises are necessary to deploy successfully

Source Code Management (SCM) Git

  • The start of CI/CD Path
  • Contains the code and the Docker files to build them
  • Pro tip: Use your Git hash in your Docker image tags

Github

  • Provides a Git Repository
  • Webhooks to trigger actions when code changes
  • Provides an API to keep track of build states
  • Manage SSH deployment keys

Jenkins

  • Is the solid standard for CI
  • Coordinates building docker images
  • Starts the tests and deployers
  • Gives us decent user interface to make sense of it all
  • Other options for Jenkins are Travis and Circle CI but we will use Jenkins.

Amazon Web Services

  • Hosted Docker Registries and Docker Containers
  • CodeCommit
  • CodeBuild
  • CodeDeploy
  • Cloud Formation
  • Code Pipeline (charts and graphs)

Docker Hosting

  • Host Docker Images on instances you control
  • Creates long-running or scheduled execution of Docker containers

Google

  • Kubernetes Engines
  • Compute engine

Docker Registry

  • Amazon
  • Google
  • Docker Hub

Enterprise Build Tools

  • Maven
  • Nexus

Jenkins Overview

We will set Jenkins and Docker in AWS

  1. Create a Security Group to set up our Jenkins's inbound policy. I allowed ports 22 and 8080 from the source internet. This is just for demo purposes. If you want a secured connection, only allow the IP you use to connect inbound.

2. Set up an instance and attach the VPC and security group you created. I will auto-assign a public IP address and attach my existing VPC and security group

 

3. Now install Jenkins in Ubuntu 24.04. Reference -> https://www.jenkins.io/doc/book/installing/linux/#debianubuntu

root@ip-172-31-2-232:~# java -version
openjdk version "21.0.6" 2025-01-21 LTS
OpenJDK Runtime Environment Temurin-21.0.6+7 (build 21.0.6+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.6+7 (build 21.0.6+7-LTS, mixed mode, sharing)
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]" \
  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins

 

4. Now access the Jenkins instance through its FQDN. By the way, you need to connect through port 8080. Check the admin password in var/lib/jenkins/secrets/initialAdminPassword.

root@ip-172-31-2-232:~# cat /var/lib/jenkins/secrets/initialAdminPassword
a892612c360f43ee913e322a3ceac712
root@ip-172-31-2-232:~# 

5. Install suggested plugins

3. Create a username and password. After that, save and finish.

4. Now that we can access our jenkins already.

5. Now install docker. Installation procedure is in https://docs.docker.com/engine/install/ubuntu/

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Verify installation

sudo docker run hello-world

 

5. Now start the docker service and enable it so it will run even after reboot.

grace@ip-172-31-2-232:~$ sudo systemctl enable docker.service
[sudo] password for grace: 
Synchronizing state of docker.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable docker
grace@ip-172-31-2-232:~$ sudo systemctl start docker.service
grace@ip-172-31-2-232:~$ systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: enabled)
     Active: active (running) since Fri 2025-04-11 21:01:33 UTC; 31min ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 5273 (dockerd)
      Tasks: 9
     Memory: 33.9M (peak: 94.7M)
        CPU: 571ms
     CGroup: /system.slice/docker.service
             └─5273 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Warning: some journal files were not opened due to insufficient permissions.
grace@ip-172-31-2-232:~$ 

6. Add both Jenkins and  user(ourselves) permission to docker

grace@ip-172-31-2-232:~$ sudo usermod -aG docker grace
grace@ip-172-31-2-232:~$ sudo usermod -aG docker jenkins

7. Reboot the instance to initialize the user in the group. Now it worked using grace

grace@ip-172-31-2-232:~$ docker run hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

grace@ip-172-31-2-232:~$ 

Check if Jenkins is allowed as well to run the docker. As you see below, Jenkins is able to run docker as well.

grace@ip-172-31-2-232:~$ sudo -u jenkins docker run hello-world:latest

[sudo] password for grace: 

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

8. Login to Jenkins. Create a New Item name docker-test and select the Freestyle project item type. Then click ok.

9. Now go to Environment and in the Build steps, choose the "execute shell". In the textbox of the "execute shell", run docker run hello-world. Click save after.

10. Click Build now

11. You see that it worked and jenkins instance can run the docker command. This is seen in build #1.


 

Docker Registry

Now let's discuss about Docker Registry. What is docker registry?

  1. Anchor point that ties architecture together
  2. Connect all steps of the pipeline
  3. Provides peace of mind

Choosing a Host

  • Traditional host with local storage
  • Put it in the existing  service within the organization (e.g Nexus)
  • Service from a cloud provider such as ECS
  • Docker Hub

Using the Traditional approach in choosing host

  • Running it on your server
  • Good option for people with existing infrastructure
  • Creates a new service you depend on
  • When it breaks, you're empowered to fix it yourself.

Let's install it!

  1. Go to https://docs.docker.com/registry/ for the instructions.

On-Premises Hosted Service

  • Nexus is very common - you may already have it
  • Uses your existing security model
  • Single point of failure
  • Can turn build-time outages into production outages

Using Docker Hub

  • Uses its own authentication and authorization system
  • Privacy is managed by an outside company
  • If its down, you have someone to yell at
  • To use this, go to https://hub.docker.com, sign up and the sign in

Using Amazon Elastic Container Registry

  1. First go to Identity and Access Management (IAM) of AWS
  2. Create an IAM role that will give the docker instance a role to read the ECS registry. Go to IAM > Roles > Select EC2 > AmazonEC2ContainerRegistryPowerUser. Then attach the IAM role to the EC2  Jenkins instance.

Elastic Container Service

  1. Create an Elastic Container Service

2. Add aws cli commands in your instance so it can execute aws cli commands from Jenkins -> https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

grace@ip-172-31-2-232:~$ aws --version
aws-cli/2.26.1 Python/3.13.2 Linux/6.8.0-1024-aws exe/x86_64.ubuntu.24

 

 3. Add it to the build steps of Jenkins. Go o to jenkins > docker-test > configure > Build steps

docker run hello-world

aws ecr get-login-password --region us-east-1 | \
docker login --username AWS --password-stdin 443370678519.dkr.ecr.us-east-1.amazonaws.com
docker tag hello-world:latest 443370678519.dkr.ecr.us-east-1.amazonaws.com/hello-world:latest
docker push 443370678519.dkr.ecr.us-east-1.amazonaws.com/hello-world:latest

 

3. Build it in Jenkins. You will see that it was successful.