How to push Docker Image to Docker Hub Registry?

This is step by step guide on how to push Docker Image to Docker Hub registry. To get started with this post, I assume that you are well familiar with how Docker works , Docker specific commands and utilities. If not,  refer my old posts.

I assume you have already pulled Ubuntu 12.04 image from the remote docker hub as shown below:

[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
ee9aa6c9b0bb ubuntu:12.04 “/bin/bash” 36 minutes ago
Up 36 minutes hungry_ptolemy

You can run the below command to get detail information of the image:

[root@localhost ~]# docker inspect ee9aa6
[{
“AppArmorProfile”: “”,
“Args”: [],
“Config”: {
“AttachStderr”: true,
“AttachStdin”: true,
“AttachStdout”: true,
“Cmd”: [
“/bin/bash”
],
“CpuShares”: 0,
“Cpuset”: “”,
“Domainname”: “”,
“Entrypoint”: null,
“Env”: null,
“ExposedPorts”: null,
“Hostname”: “ee9aa6c9b0bb”,
“Image”: “ubuntu:12.04”,
“MacAddress”: “”,
“Memory”: 0,
“MemorySwap”: 0,
“NetworkDisabled”: false,
“OnBuild”: null,
“OpenStdin”: true,
“PortSpecs”: null,
“StdinOnce”: true,
“….
………
},
“HostnamePath”:
“/var/lib/docker/containers/ee9aa6c9b0bb9312851cc1c8775921eba45d56d0f3ba42c1e0a
0b2af92a70df9/hostname”,
“HostsPath”:
“/var/lib/docker/containers/ee9aa6c9b0bb9312851cc1c8775921eba45d56d0f3ba42c1e0a
0b2af92a70df9/hosts”,
“Id”: “ee9aa6c9b0bb9312851cc1c8775921eba45d56d0f3ba42c1e0a0b2af92a70df9”,
“Image”:
“ac6b0eaa3203c07cb413842c9da6cbbbcf352504c43697ecba449395886e3ae1”,
“MountLabel”: “”,
“Name”: “/hungry_ptolemy”,
“NetworkSettings”: {
“Bridge”: “docker0”,
“Gateway”: “172.17.42.1”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“IPAddress”: “172.17.0.11”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“LinkLocalIPv6Address”: “fe80::42:acff:fe11:b”,
“LinkLocalIPv6PrefixLen”: 64,
“MacAddress”: “02:42:ac:11:00:0b”,
“PortMapping”: null,
“Ports”: {}
},
“Path”: “/bin/bash”,
“ProcessLabel”: “”,
“ResolvConfPath”:
“/var/lib/docker/containers/ee9aa6c9b0bb9312851cc1c8775921eba45d56d0f3ba42c1e0a
0b2af92a70df9/resolv.conf”,

}

Enter into the Docker image as shown below:

[root@localhost ~]# docker run -it collabnix/puppet4docker:latest /bin/bash
root@eedc8a990076:/#

Now let’s install software into the container. Say, I want to configure Puppet into the container to orchestrate the docker container itself.

root@eedc8a990076:/# apt-get install puppet

root@eedc8a990076:/#cd /etc/puppet/modules

root@eedc8a990076:/etc/puppet/modules# wget https://forgeapi.puppetlabs.com/v3/files/garethr-docker-4.0.2.tar.gz –no- check-certificate
–2015-05-19 06:47:44– https://forgeapi.puppetlabs.com/v3/files/garethr- docker-4.0.2.tar.gz
connected.
WARNING: cannot verify forgeapi.puppetlabs.com’s certificate, issued by `/C=US/O=GeoTrust Inc./CN=GeoTrust SSL CA – G2′:
Unable to locally verify the issuer’s authority.
Proxy request sent, awaiting response… 200 OK
Length: unspecified [application/octet-stream]
Saving to: `garethr-docker-4.0.2.tar.gz’

[ <=> ] 34,484 –.-K/s in 0.05s

2015-05-19 06:47:46 (636 KB/s) – `garethr-docker-4.0.2.tar.gz’ saved [34484]

root@eedc8a990076:/etc/puppet/modules# tar xvzf garethr-docker-4.0.2.tar.gz
garethr-docker-4.0.2/
garethr-docker-4.0.2/checksums.json
garethr-docker-4.0.2/CONTRIBUTING.md
garethr-docker-4.0.2/files/
garethr-docker-4.0.2/Gemfile
garethr-docker-4.0.2/Gemfile.lock
garethr-docker-4.0.2/Guardfile
garethr-docker-4.0.2/templates/etc/init.d/docker-run.erb
garethr-docker-4.0.2/templates/etc/default/docker.erb
garethr-docker-4.0.2/templates/etc/conf.d/docker.erb

garethr-docker-4.0.2/manifests/systemd_reload.pp
garethr-docker-4.0.2/log/default/
garethr-docker-4.0.2/junit/centos-70-x64/2015-04-21_11_59_33/
garethr-docker-4.0.2/files/service-overrides-archlinux.conf
root@eedc8a990076:/etc/puppet/modules# mv garethr-docker-4.0.2 docker

Let’s configure Puppet to include Docker class as shown below:

#vi /etc/puppet/manifests/site.pp

include ‘docker’

Save the file.

You can now restart the puppet service as shown below:

root@eedc8a990076:/etc/puppet# service puppet restart
* Restarting puppet agent [ OK ]

So our application is ready. It’s time to push this image to the remote Docker hub.

Docker Commit:

Before pushing the image to Docker Hub registry, the image need to be committed just like git commit.We can commit a copy of this container to an image using the docker commit command.

[root@localhost ~]# docker commit -m “Puppet for Docker” -a “Ajeet Raina” eedc8a990076 collabnix/puppet-for-docker:v1.0

As shown above, we’ve specified two flags: -m and -a.

The -m flag allows us to specify a commit message, much like you would with a commit on a version control system. The-a flag allows us to specify an author for our update.

We can then commit a copy of this container to an image using the docker commit command.

We’ve also specified the container we want to create this new image from,  eedc8a990076(the ID we recorded earlier) and we’ve specified a target for the image:It consists of a  user, collabnix, that we’re writing this image to. We’ve also specified the name of the image, here we’re keeping the original image name puppet-for-docker. Finally we’re specifying a tag for the image: v1.0.

Hence, its time to push it to the remote Docker hub. Let’s do it quick:

[root@localhost ~]# docker push collabnix/puppet-for-docker:v1.0
The push refers to a repository [collabnix/puppet-for-docker] (len: 1)
Sending image list
Pushing repository collabnix/puppet-for-docker (1 tags)
c50f7e0846e6: Image already pushed, skipping
fd248b999044: Image already pushed, skipping
9f91f850df24: Image already pushed, skipping
ac6b0eaa3203: Image already pushed, skipping
abb227dc9aed: Image successfully pushed
Pushing tag for rev [abb227dc9aed] on {https://cdn-registry-
1.docker.io/v1/repositories/collabnix/puppet-for-docker/tags/v1.0}
[root@localhost ~]#

Finally, we have pushed it to the remote Docker hub. Let’s verify.

Verifying the Image:
To verify the content, lets try to pull it on another machine:

[root@puppetmastr ~]# docker search puppet-for-docker
INFO[0130] GET /v1.18/images/search?term=puppet-for-docker
INFO[0130] +job search(puppet-for-docker)
INFO[0130] +job resolve_repository(puppet-for-docker)
INFO[0130] -job resolve_repository(puppet-for-docker) = OK (0)
INFO[0131] -job search(puppet-for-docker) = OK (0)
NAME DESCRIPTION
STARS OFFICIAL AUTOMATED
devopsil/puppet Dockerfile for a container with puppet
ins… 8 [OK]
lukasz/docker-puppet-openssl-nginx This image is derived from
https://index.d… 1 [OK]
collabnix/puppet-for-docker
0
nrvale0/ubuntu-puppet-agent Ubuntu 14.04 Docker container with pre-
ins… 0 [OK]
nrvale0/centos-puppet-agent CentOS 6 Docker container with pre-
install… 0 [OK]
[root@puppetmastr ~]# docker pull collabnix/puppet-for-docker:v1.0
INFO[0173] POST /v1.18/images/create?fromImage=collabnix%2Fpuppet-for-docker
%3Av1.0
INFO[0173] +job pull(collabnix/puppet-for-docker, v1.0)
INFO[0173] +job resolve_repository(collabnix/puppet-for-docker)
INFO[0173] -job resolve_repository(collabnix/puppet-for-docker) = OK (0)
Pulling repository collabnix/puppet-for-docker
abb227dc9aed: Pulling fs layer
c50f7e0846e6: Download complete
fd248b999044: Download complete
9f91f850df24: Download complete
ac6b0eaa3203: Download complete

Hence one can easily verify the puppet software through this container.

Hope you find it useful.

Cheers ~

Leave a Reply

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