Container Registry Practice - Creating Container Registry

Table of Contents

Overview

Pre-Requisites

Practice 1: Sign in to OCI Console and create VCN and Docker Registry

Practice 2: Create ssh keys and compute instance

Practice 3: SSH to Compute Instance install Docker and push images to registry

Practice 4: Delete the resources

Overview

In this lab we will create Docker registry in OCI, we will then install Docker on a compute instance and push and pull images to/from this registry.

Oracle Cloud Infrastructure Registry is an Oracle-managed registry that enables you to simplify your development to production workflow. Oracle Cloud Infrastructure Registry makes it easy for you as a developer to store, share, and manage development artifacts like Docker images. And the highly available and scalable architecture of Oracle Cloud Infrastructure ensures you can reliably deploy your applicationsYou can use Oracle Cloud Infrastructure Registry as a private Docker registry for internal use, pushing and pulling Docker images to and from the Registry using the Docker V2 API and the standard Docker command line interface (CLI). You can also use Oracle Cloud Infrastructure Registry as a public Docker registry, enabling any user with internet access and knowledge of the appropriate URL to pull images from public repositories in Oracle Cloud Infrastructure Registry.

Pre-Requisites

Practice-1: Sign in to OCI Console and create VCN and Docker Registry

Note: OCI UI is being updated thus some screenshots in the instructions might be different than actual UI

Before You Begin

  1. Sign in using your tenant name, user name and password.

  2. Once signed in select the compartment assigned to you from drop down menu on left part of the screen

  3. From the OCI Services menu,click Virtual Cloud Network under Networking and click Create Virtual Cloud Network

NOTE: Ensure the correct Compartment is selected under COMPARTMENT list

  1. Fill out the dialog box:

We will now create an Auth Token. This token will be used to login to connect to OCI Docker registry from the Docker computeinstance that will be created later one

  1. Click user icon (Top Right of OCI Console Window) and then User Settings and then Auth Token

  2. Click Generate Token, Provide a description, and click Generate Token

  3. Click Copy (Under the token) to copy the token

  4. If Notepad is not launched already, click the Apps icon and click notepad.

  1. Paste the Auth Token in Note pad(using your mouse/touch pad or Ctrl v).
  2. Switch to the OCI console window.

HINT: You can swap between OCI window and any other application(git-bash etc) by clicking the switch window icon

  1. From OCI Services menu, click Registry(OCIR) under Developer Services

  2. Click Create Repository. Provide Repository name (all Lowercase), Check Public and click Submit

  3. Once created, verify there are no existing images in the repository (as shown in OCI console)

We now have a Docker registry and Auth token (to validate login to the registry). Next we will create a Public/Private key pair and then compute instance to test pushing and pulling images from the registry.

Practice 2: Create ssh keys and compute instance

  1. Open built in Git bash application and generate ssh keys

  2. Click the Apps icon in the toolbar and select Git-Bash to open a terminal window.

  3. Enter command:

    ssh-keygen
    

    HINT: You can swap between OCI window, git-bash sessions and any other application (Notepad, etc.) by clicking the Switch Window icon

  1. Press Enter When asked for ‘Enter File in which to save the key’, ‘Created Directory, ‘Enter passphrase’, and ‘Enter Passphrase again.

  2. You should now have the Public and Private keys:

/C/Users/ PhotonUser/.ssh/id_rsa (Private Key) /C/Users/PhotonUser/.ssh/id_rsa.pub (Public Key)

NOTE: id_rsa.pub will be used to create Compute instance and id_rsa to connect via SSH into compute instance.

HINT: Enter command: (No Spaces)

 cd /C/Users/PhotonUser/.ssh

and then

 ls

to verify the two files exist.

  1. In git-bash Enter command:
    cat /C/Users/PhotonUser/.ssh/id_rsa.pub
    

    , highlight the key and copy

  1. Click the apps icon, launch notepad and paste the key in Notepad (as backup)

  1. Switch to the OCI console. From OCI servies menu, Click Instances under Compute

  2. Click Create Instance. Fill out the dialog box:

  1. Click Create

NOTE: If ‘Service limit’ error is displayed choose a different shape such as VM.Standard.E2.2 OR VM.Standard2.2

Next we will ssh to the compute instance and install Docker.

Practice 3: SSH to Compute Instance install Docker and push images to registry

  1. In git-bash type cd /C/Users/PhotonUser/.ssh

  2. Enter command
    ls
    

    and verify id_rsa file exists

  3. Enter command
    ssh –i id_rsa opc@<PUBLIC_IP_OF_COMPUTE_INSTANCE>
    

    NOTE: User name is opc

HINT: If ‘Permission denied error’ is seen, ensure you are using ‘-i’ in the ssh command

  1. Enter ‘Yes’ when prompted for security message

  1. Verify opc@<COMPUTE_INSTANCE_NAME(reserved-ip-instance1 in this case) appears on the prompt

  2. Enter command:
    sudo yum install -y yum-utils device-mapper-persistent-data lvm2
    

  3. Enter command:
    sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo**
    

  4. Enter command:
    sudo yum install docker-ce –y
    

    (Wait for ‘Complete’message)

  5. Enter command:
    sudo systemctl enable docker
    
  6. Enter command:
    sudo systemctl start docker
    
  7. Enter command: (To add user opc to Docker)
    sudo usermod -aG docker opc
    
  8. Docker is installed and user opc enabled to use Docker. Enter Command
    
    

    to logout of ssh session on compute instance and then ssh back in to the compute instance. Enter command Docker images and ensure no error is displayed

  9. We will now pull a example image from Docker registry to the compute instance. Enter Command:
    docker image pull alpine
    

    Verify image pull was successful, Enter Command

    Docker images
    

    and verify alpine is present

  10. Now we will push this image to Docker registry created in OCI. First login to Registry in OCI. Enter command
    docker login <Region_Name_Code>.ocir.io
    

    NOTE: Region name code are, fra for Frankfurt, iad for Ashburn, lhr for London, phx for Phoenix.

HINT: Your region is shown on top right corner of OCI console window

  1. Verify Login Succeeded message is displayed.

  2. Next we will tag the image that we pulled from the web. Enter command
    docker images
    

    and note down the image id of alpine. Enter command: (No Spaces)

    docker tag <image_id>  <Region_Name_Code>.ocir.io/<TenancyName>/<docker_registry_name>:<image_name> 
    
  3. Verify the tag was created, Enter command
    docker images
    

    and verify version x.y.test is present. x and y will be the numeric version number)

NOTE: In below example:

  1. We will now push the image to docker registry in OCI. Enter command:
    docker push <Region_Name_Code>.ocir.io/<Tenancy_Name>/<docker_registry_name>:<image_name>** (No Spaces)
    

    NOTE: In below example:

    • is **iad**
    • is **us_training**
    • is **docker-test-image**
    • is **version4.0.test** ![]( img/OCIR_HOL0029.PNG)
  2. Switch to OCI window and navigate to your registry. Newly pushed image should be visible.

HINT: Refresh the browser window if image is not displayed

  1. Switch to compute instance ssh window. Enter command
    docker pull <Region_Name_Code>.ocir.io/<Tenancy_Name>/<docker_registry_name>:<image_name>**  (No Spaces)    
    
  2. Verify the pull command was successful

HINT: We are pulling the same image that we just pushed.

We now have a working Docker registry and can successfully push and pull images to/from it.

Practice 4: Delete the resources

  1. Switch to OCI console window

  2. If your Compute instance is not displayed, From OCI services menu Click Instances under Compute

  3. Locate first compute instance, Click Action icon and then Terminat

  4. Make sure Permanently delete the attached Boot Volume is checked, Click Terminate Instance. Wait for instance to fully Terminate

  1. From OCI services menu Click Virtual Cloud Networks under Networking, list of all VCNs will appear.

  2. Locate your VCN , Click Action icon and then Terminate. Click Delete All in the Confirmation window. Click Close once VCN is deleted

  3. From OCI Services menu, click Registry(OCIR) under Developer Services, click Registry Name, Under Action click Delete Repository ,click Delete in confirmation window

Congratulations! You have successfully completed Creating Docker Registry on Oracle Cloud Infrastructure .In this lab we successfully set up a Registry in OCI, Installed Docker on compute instance and then pushed and pulled images from the registry.