{"id":23603,"date":"2021-09-15T04:52:44","date_gmt":"2021-09-15T04:52:44","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=23603"},"modified":"2025-07-12T05:41:42","modified_gmt":"2025-07-12T05:41:42","slug":"docker-lab-excercise-assignment-5-docker-registry","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/docker-lab-excercise-assignment-5-docker-registry\/","title":{"rendered":"Docker Lab, Excercise &#038; Assignment &#8211; 5 &#8211; Docker Registry"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Lesson Objectives<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Understanding where images come from<\/li><li>Pulling a Docker image from Docker Hub<\/li><li>Pushing a Docker image to Docker Hub<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Getting an image from Docker Hub<\/h2>\n\n\n\n<p><a href=\"https:\/\/hub.docker.com\/\" target=\"_blank\" rel=\"noopener\">Docker Hub<\/a>&nbsp;is the place where open Docker images are stored. When we ran our first image by typing<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">docker run --rm -p 8787:8787 rocker\/verse\n<\/code><\/span><\/pre>\n\n\n<p>the software first checked if this image is available on your computer and since it wasn\u2019t it downloaded the image from Docker Hub. So getting an image from Docker Hub works sort of automatically. If you just want to pull the image but not run it, you can also do<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">docker pull rocker\/verse\n<\/code><\/span><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Getting an image to Docker Hub<\/h2>\n\n\n\n<p>Imagine you made your own Docker image and would like to share it with the world you can sign up for an account on&nbsp;<a href=\"https:\/\/hub.docker.com\/\" target=\"_blank\" rel=\"noopener\">https:\/\/hub.docker.com\/<\/a>. After verifying your email you are ready to go and upload your first docker image.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Log in on&nbsp;<a href=\"https:\/\/hub.docker.com\/\" target=\"_blank\" rel=\"noopener\">https:\/\/hub.docker.com\/<\/a><\/li><li>Click on&nbsp;<em>Create Repository<\/em>.<\/li><li>Choose a name (e.g.&nbsp;verse_gapminder) and a description for your repository and click&nbsp;<em>Create<\/em>.<\/li><li>Log into the Docker Hub from the command line<code>docker login --username=yourhubusername --email=youremail@company.com<\/code>just with your own user name and email that you used for the account. Enter your password when prompted. If everything worked you will get a message similar to<code>WARNING: login credentials saved in \/home\/username\/.docker\/config.json Login Succeeded<\/code><\/li><li>Check the image ID using<code>docker images<\/code>and what you will see will be similar to<\/li><\/ol>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">REPOSITORY              TAG       IMAGE ID         CREATED           SIZE\nverse_gapminder_gsl     latest    023ab91c6291     3 minutes ago     1.975 GB\nverse_gapminder         latest    bb38976d03cf     13 minutes ago    1.955 GB\nrocker\/verse            latest    0168d115f220     3 days ago        1.954 GB\n<\/code><\/span><\/pre>\n\n\n<p>and tag your image<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">docker tag bb38976d03cf yourhubusername\/verse_gapminder:firsttry<\/code><\/span><\/pre>\n\n\n<p>The number must match the image ID and&nbsp;<code>:firsttry<\/code>&nbsp;is the tag. In general, a good choice for a tag is something that will help you understand what this container should be used in conjunction with, or what it represents. If this container contains the analysis for a paper, consider using that paper\u2019s DOI or journal-issued serial number; if it\u2019s meant for use with a particular version of a code or data version control repo, that\u2019s a good choice too &#8211; whatever will help you understand what this particular image is intended for.<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"6\"><li>Push your image to the repository you created<code>docker push yourhubusername\/verse_gapminder<\/code><\/li><\/ol>\n\n\n\n<p>Your image is now available for everyone to use.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Saving and loading images<\/h2>\n\n\n\n<p>Pushing to Docker Hub is great, but it does have some disadvantages:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Bandwidth &#8211; many ISPs have much lower upload bandwidth than download bandwidth.<\/li><li>Unless you\u2019re paying extra for the private repositories, pushing equals publishing.<\/li><li>When working on some clusters, each time you launch a job that uses a Docker container it pulls the container from Docker Hub, and if you are running many jobs, this can be really slow.<\/li><\/ol>\n\n\n\n<p>Solutions to these problems can be to save the Docker container locally as a a tar archive, and then you can easily load that to an image when needed.<\/p>\n\n\n\n<p>To save a Docker image after you have pulled, committed or built it you use the&nbsp;<code>docker save<\/code>&nbsp;command. For example, lets save a local copy of the&nbsp;<code>verse_gapminder<\/code>&nbsp;docker image we made:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">docker<\/span> <span class=\"hljs-selector-tag\">save<\/span> <span class=\"hljs-selector-tag\">verse_gapminder<\/span> &gt; <span class=\"hljs-selector-tag\">verse_gapminder<\/span><span class=\"hljs-selector-class\">.tar<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>If we want to load that Docker container from the archived tar file in the future, we can use the docker load command:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">docker<\/span> <span class=\"hljs-selector-tag\">load<\/span> <span class=\"hljs-selector-tag\">--input<\/span> <span class=\"hljs-selector-tag\">verse_gapminder<\/span><span class=\"hljs-selector-class\">.tar<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>You need to tag your image correctly first with your&nbsp;registryhost:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST\/][USERNAME\/]NAME[:TAG]  <\/pre>\n\n\n\n<p>Then docker push using that same tag.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker push NAME[:TAG]  <\/pre>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker tag 518a41981a6a myRegistry.com\/myImage  docker push myRegistry.com\/myImage<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">&nbsp;<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">Challenge Questions<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Download your partner\u2019s image. How did that compare speed-wise to downloading the verse image the first time?<\/li><li>Browse Docker Hub for interesting images. What could be useful to you?<\/li><li>Discuss the pros and cons of using Docker images from someone you don\u2019t know with your neighbour.<\/li><\/ul>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_11369\"><iframe loading=\"lazy\"  id=\"_ytid_51006\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_11369\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Lesson Objectives Understanding where images come from Pulling a Docker image from Docker Hub Pushing a Docker image to Docker Hub Getting an image from Docker Hub Docker Hub&nbsp;is the&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[4862],"tags":[],"class_list":["post-23603","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/23603","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=23603"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/23603\/revisions"}],"predecessor-version":[{"id":24184,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/23603\/revisions\/24184"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=23603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=23603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=23603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}