Docker using private registry

There is an easy way to define Docker container using Dockerfile, you may find it in previous article. There I installed ActiveMQ to Vagrant in Docker without using any registry. The other way to do it is private Docker registry. I will install now MongoDB in a Docker container w/o Dockerfile.

First we need to prepare private registry. I have a system with docker installed and I’m just running registry and registry-ui containers there:

docker run -d -p 5000:5000 registry
docker run -d -p 8080:8080 atcol/docker-registry-ui

Than I need to add registry url in registry ui. In http://10.100.63.193:8080 (that’s my host) I’m adding new registry (url: http://10.100.63.193:5000, version: v1).

Next step is installing MongoDB into ubuntu container:

docker run -t -i --name mongo ubuntu /bin/bash

And something like: apt-get install mongodb inside docker shell. After that I need to create Docker image from current container:

docker commit -m "first commit" mongo 10.100.63.193:5000/mongo
docker rm mongo
docker run --name mongo -d -p 27017:27017 -v /data --entrypoint /usr/bin/mongod 10.100.63.193:5000/mongo --dbpath /data
docker commit -m "first commit" mongo 10.100.63.193:5000/mongo

Here I’m creating a 10.100.63.193:5000/mongo image from mongo container. That I define some default variables like expose for 27017 port, volume /data and /usr/bin/mongod with --dbpath /data arguments as entry point. That means new mongo container will start mongo service with /data/ shared volume and 27017 port, mapped to the host system.

Volume /data means that this dir inside container basically is not part of that container. You can share volumes between different containers and you can map volume to specific host folder. I will do that late.

Now I need to push my image into registry: docker push 10.100.63.193:5000/mongo. You can also specify tag like 10.100.63.193:5000/mongo:t1 if you need to save that version forever. To update 10.100.63.193:5000/mongo I just need to change stuff inside that container and commit into image with the same name.

On my target machine I’m executing:

docker pull 10.100.63.193:5000/mongo
docker run -d -p 27017:27017 -v /var/data:/data 10.100.63.193:5000/mongo

So it will download the container and run it. And it will store all mongo data into /var/data host folder. So I can do whatever I want with container and be not afraid about my real data.

That’s it. I can now add this container into my Vagrant file or deploy it directly to real system.

One thought on “Docker using private registry

  1. I have a vagrantfile which was creating a VM in aws. After That I was using docker provisioner which installs tutum\mysql image on that VM. Now since we need to use our custom docker registry for image pulling, please suggest me how can I do it. Also how can I install the certificate in the VM through vagarnt file. The image can be pulled from the new docker registry as below.

    docker pull ec2-0-0-0-0.xxx.amazonaws.com:8080/mysql

    Please find below vagrant file

    Vagrant.configure("2") do |config|

    config.vm.box = “ubuntu_aws”
    config.vm.box_url = “https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box”
    config.vm.synced_folder “../.”, “/vagrant”, id: “vagrant-root”, type: “docker”,disabled: true
    config.vm.provider :aws do |aws, override|
    aws.keypair_name = “XXX-key-pair”
    override.ssh.private_key_path = “C:/Users/XXX/Desktop/ppk/XXX-key-pair.pem”
    aws.access_key_id = “XXXXXXXXX”
    aws.secret_access_key = “xxxxxxxxxx”
    aws.instance_type = “t2.micro”
    aws.security_groups = [“sg-xxxxxx”]
    aws.ami = “ami-xxxxxx”
    override.ssh.username = “ubuntu”
    aws.subnet_id = “xxxxxxx”
    aws.associate_public_ip=”true”

    aws.tags = {
    'Name' => 'XXX-test',
    }

    end

    config.vm.provision “docker” , images:[“tutum/mysql”,”dockerfile/redis”]

    config.vm.provision “docker” do |d|
    d.run “tutum/mysql”,args: “-p 3306:3306”
    #d.run “dockerfile/redis”,args: “-p 6379:6379”

    end

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax