How to install Docker Registry 2.x on AWS with storage on S3

How to install Docker Registry 2.x on AWS with storage on S3

###1. Create a new bucket for Docker Registry on S3

Go to AWS Services -> S3 and create a new bucket “my-docker-registry” on your region

###2. Create a user to allow our docker registry to access the new bucket

Goto AWS Services -> IAM -> Create New Users

Enter a name for your user (e.g. docker-registry) and click on Create. Write down (or download the csv file with) your Access Key and Secret Access Key that we’ll need when running the Docker container. Go back to your users list and select the one you just created.

Under the Permission section, click on Attach User Policy. In the next screen, you will be presented with multiple choices: select Custom Policy.Here’s the content of the custom policy:

    {
		"Version": "2012-10-17",
	    "Statement": [
           {
                "Effect": "Allow",
                "Action": "s3:ListAllMyBuckets",
                "Resource": "arn:aws:s3:::*"
           },
           {
                "Effect": "Allow",
                "Action": [
                     "s3:ListBucket",
                     "s3:GetBucketLocation"
                ],
                "Resource": "arn:aws:s3:::my-docker-registry"
           },
           {
                "Effect": "Allow",
                "Action": [
                     "s3:PutObject",
                     "s3:GetObject",
                     "s3:DeleteObject"
                ],
                "Resource": "arn:aws:s3:::my-docker-registry/*"
        }
      ]
    }

This will allow the user (i.e. the registry) to manage (read/write) content on the bucket (make sure to use the bucket name you previously defined when setting up AWS S3).

To sum it up: when you’ll be pushing Docker images from your local machine to your repository, the server will be able to upload them to S3.

###3. Create new instance for the registry:

  • Instance type: m3.xlarge based on Ubuntu server ubuntu-trusty-14.04
  • Subnet: yoursubnet
  • Zone: yourzone
  • Key-pair: yourkeypair

Connect with ssh to your new instance

4. Install docker

 sudo apt-get -y install docker

5. Run the registry

 docker run --name registry2 -d \
 -e REGISTRYSTORAGE=s3 \
 -e REGISTRYSTORAGES3REGION=<your region> \
 -e REGISTRYSTORAGES3BUCKET=my-docker-registry \
 -e REGISTRYSTORAGES3ACCESSKEY=XXXXXX \
 -e REGISTRYSTORAGES3SECRETKEY=XXXXXX \
 -e SEARCHBACKEND=sqlalchemy
 -p 5000:5000
 -p 5001:5001
 registry:2.0.1

List the tags for specific docker in your new private registry

http://[registry ip]:5000/v2/[image]/tags/list

like

http://[my registry ip]:5000/v2/myproduct/docker1/tags/list

DevOps Architect

DevOps Group
Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com