{"id":798,"date":"2020-07-15T14:32:00","date_gmt":"2020-07-15T14:32:00","guid":{"rendered":"https:\/\/blog.samarthya.me\/wps\/?p=798"},"modified":"2020-07-15T14:32:02","modified_gmt":"2020-07-15T14:32:02","slug":"dockerfile","status":"publish","type":"post","link":"https:\/\/blog.samarthya.me\/wps\/2020\/07\/15\/dockerfile\/","title":{"rendered":"Dockerfile"},"content":{"rendered":"\n<p><code>docker build<\/code> builds a docker image by reading instructions (directives) from a text file called <code>Dockerfile<\/code><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>The build is run by the Docker daemon, not by the CLI<\/p><\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">Hello World!<\/h2>\n\n\n\n<p>I would move in stages, like a good learning guide always recommends.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Lesson 1 - Using basic Dockerfile to compose an image\nFROM alpine:3.7 \n# Using alpine 3.7 latest on the day.\nCMD &#91;\"echo\",\"Hello world!\"]<\/code><\/pre>\n\n\n\n<p>The file above uses two directives and an image<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Format: directive<\/h3>\n\n\n\n<p>Every directive you write in your docker file would follow a template<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># INSTRUCTION arguments\nFROM alpine:3.7<\/code><\/pre>\n\n\n\n<p><code>FROM<\/code> directive identifies the parent image <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">alpine<\/h3>\n\n\n\n<p>This is a 5mb image small and convenient to get started in our case. You can find more details on how to use it <a href=\"https:\/\/hub.docker.com\/_\/alpine\">here<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker build -t samarthya\/ahello:1.0 .<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Sending build context to Docker daemon  2.048kB\nStep 1\/2 : FROM alpine:3.7\n ---> 6d1ef012b567\nStep 2\/2 : CMD &#91;\"echo\",\"Hello world!\"]\n ---> Running in 4c96833eaeb6\nRemoving intermediate container 4c96833eaeb6\n ---> 460a990ca06c\nSuccessfully built 460a990ca06c\nSuccessfully tagged samarthya\/ahello:1.0<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>docker image ls\nREPOSITORY                           TAG                                              IMAGE ID            CREATED              SIZE\nsamarthya\/ahello                     1.0                                              460a990ca06c        About a minute ago   4.21MB<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>docker image history 460a990ca06c\nIMAGE               CREATED              CREATED BY                                      SIZE                COMMENT\n460a990ca06c        About a minute ago   \/bin\/sh -c #(nop)  CMD &#91;\"echo\" \"Hello world!\u2026   0B                  \n6d1ef012b567        16 months ago        \/bin\/sh -c #(nop)  CMD &#91;\"\/bin\/sh\"]              0B                  \n&lt;missing>           16 months ago        \/bin\/sh -c #(nop) ADD file:aa17928040e31624c\u2026   4.21MB           <\/code><\/pre>\n\n\n\n<p>A simple execution allows to see the desired output.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run --name hello samarthya\/ahello:1.0\nHello world!<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Reference<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>https:\/\/hub.docker.com\/_\/alpine<\/li><li><a href=\"https:\/\/docs.docker.com\/engine\/reference\/builder\/#format\">https:\/\/docs.docker.com\/engine\/reference\/builder\/#format<\/a><\/li><\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>docker build builds a docker image by reading instructions (directives) from a text file called Dockerfile The build is run by the Docker daemon, not by the CLI Hello World! I would move in stages, like a good learning guide always recommends. The file above uses two directives and an image Format: directive Every directive [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":803,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[34],"tags":[82],"class_list":["post-798","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-technical","tag-docker","post_format-post-format-image"],"_links":{"self":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/798","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/comments?post=798"}],"version-history":[{"count":0,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/798\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media\/803"}],"wp:attachment":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media?parent=798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/categories?post=798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/tags?post=798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}