Saturday, June 13, 2015

Create your own Docker Registry with S3

The purpose of this post is to be able to deploy your own custom image to ElasticBeanstalk using docker registry through storing the images on Amazon S3.

Let's begin by cloning Docker Registry 2.0.

git clone https://github.com/docker/distribution.git

Generate self-signed certificates.

cd distribution
mkdir certs
openssl req \
         -newkey rsa:2048 -nodes -keyout certs/domain.key \
         -x509 -days 365 -out certs/domain.crt

Add TLS to config.yml


vi ./cmd/registry/config.yml

Add the tls block to the http section like the following:

http:
    addr: :5000
    secret: asecretforlocaldevelopment
    debug:
        addr: localhost:5001
    tls: 
        certificate: /go/src/github.com/docker/distribution/certs/domain.crt
        key: /go/src/github.com/docker/distribution/certs/domain.key

Remove filesystem settings and use AWS s3 as repository storage:

storage:
   #filesystem:
   #        rootdirectory: /tmp/registry
   s3:
      accesskey: awsaccesskey
      secretkey: awssecretkey
      region: us-west-1
      bucket: bucketname
      encrypt: true
      secure: true
      v4auth: true
      chunksize: 5242880
      rootdirectory: /s3/object/name/prefix

Settings: http://docs.docker.com/registry/configuration/#storage

Save this.

Build the image with a name (ex. docker_registry)

> docker build -t docker_registry .

Tag it. Note that I am using boot2docker on MacOSX. You can get your IP address by running "boot2docker ip".

> docker tag docker_registry:latest 192.168.59.103:5000/docker_registry:latest

Run the registry.

> docker run -p 5000:5000 docker_registry

If you try to push your an image, you will get a error saying you need to add an insecure registry.

> boot2docker ssh "echo $'EXTRA_ARGS=\"--insecure-registry 192.168.59.103:5000\"' | sudo tee -a /var/lib/boot2docker/profile && sudo /etc/init.d/docker restart"

Push an image:

> docker push 192.168.59.103:5000/{image}

No comments:

Post a Comment