Docker : Brief Introduction - Part 2

Initially, Docker was used as a Linux containerization tool. Support for other environments such as Windows and MacOS was added later. In this post, let us take a look at how to install Docker in the Linux platform and how to create the Docker images.
Installation of Docker at Linux (Ubuntu or similar) machine
Installation of Docker at Linux is usually pretty straightforward.
1) Open the Linux terminal
2) Run the command “sudo apt-get -y install docker.io”
<div id="crayon-69432b7200b54080427848" class="crayon-syntax crayon-theme-powershell crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
<div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-copy-button" title="Copy"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div></div></div>
<div class="crayon-info" style="min-height: 18px !important; line-height: 18px !important;"></div>
<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">
falcon@falcon-Satellite-L50D-B:~$ sudo apt-get -y install docker.io
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages were automatically installed and are no longer required:
fonts-sil-gentium fonts-sil-gentium-basic fonts-stix libabw-0.1-1v5 libcdr-0.1-1 libcmis-0.5-5v5 libe-book-0.1-1 libeot0 libetonyek-0.1-1 libfreehand-0.1-1
libglew1.13 libhsqldb1.8.0-java libmspub-0.1-1 libmwaw-0.3-3 libodfgen-0.1-1 liborcus-0.10-0v5 libpagemaker-0.0-0 libreoffice-sdbc-firebird librevenge-0.0-0
libservlet3.1-java libvisio-0.1-1 libwpd-0.10-10 libwpg-0.3-3 libwps-0.4-4 linux-headers-4.4.0-62 linux-headers-4.4.0-62-generic linux-image-4.4.0-62-generic
linux-image-extra-4.4.0-62-generic linux-signed-image-4.4.0-62-generic lp-solve
Use ‘sudo apt autoremove’ to remove them.
The following additional packages will be installed:
cgroupfs-mount containerd runc ubuntu-fan
…
…
Setting up docker.io (1.12.6-0ubuntu1~16.04.1) …
Adding group docker' (GID 131) ...
Done.
Setting up ubuntu-fan (0.9.2) ...
Processing triggers for systemd (229-4ubuntu16) ...
Processing triggers for ureadahead (0.100.0-19) ...
falcon@falcon-Satellite-L50D-B:~$ </textarea></div>
<div class="crayon-main" style="">
<table class="crayon-table">
<tr class="crayon-row">
<td class="crayon-nums " data-settings="show">
<div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;"><div class="crayon-num" data-line="crayon-69432b7200b54080427848-1">1</div><div class="crayon-num crayon-striped-num" data-line="crayon-69432b7200b54080427848-2">2</div><div class="crayon-num" data-line="crayon-69432b7200b54080427848-3">3</div><div class="crayon-num crayon-striped-num" data-line="crayon-69432b7200b54080427848-4">4</div><div class="crayon-num" data-line="crayon-69432b7200b54080427848-5">5</div><div class="crayon-num crayon-striped-num" data-line="crayon-69432b7200b54080427848-6">6</div><div class="crayon-num" data-line="crayon-69432b7200b54080427848-7">7</div><div class="crayon-num crayon-striped-num" data-line="crayon-69432b7200b54080427848-8">8</div><div class="crayon-num" data-line="crayon-69432b7200b54080427848-9">9</div><div class="crayon-num crayon-striped-num" data-line="crayon-69432b7200b54080427848-10">10</div><div class="crayon-num" data-line="crayon-69432b7200b54080427848-11">11</div><div class="crayon-num crayon-striped-num" data-line="crayon-69432b7200b54080427848-12">12</div><div class="crayon-num" data-line="crayon-69432b7200b54080427848-13">13</div><div class="crayon-num crayon-striped-num" data-line="crayon-69432b7200b54080427848-14">14</div><div class="crayon-num" data-line="crayon-69432b7200b54080427848-15">15</div><div class="crayon-num crayon-striped-num" data-line="crayon-69432b7200b54080427848-16">16</div><div class="crayon-num" data-line="crayon-69432b7200b54080427848-17">17</div><div class="crayon-num crayon-striped-num" data-line="crayon-69432b7200b54080427848-18">18</div><div class="crayon-num" data-line="crayon-69432b7200b54080427848-19">19</div><div class="crayon-num crayon-striped-num" data-line="crayon-69432b7200b54080427848-20">20</div><div class="crayon-num" data-line="crayon-69432b7200b54080427848-21">21</div><div class="crayon-num crayon-striped-num" data-line="crayon-69432b7200b54080427848-22">22</div></div>
</td>
<td class="crayon-code"><div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><div class="crayon-line" id="crayon-69432b7200b54080427848-1"><span class="crayon-i">falcon</span><span class="crayon-sy">@</span><span class="crayon-i">falcon</span>-<span class="crayon-i">Satellite</span>-<span class="crayon-i">L50D</span>-<span class="crayon-i">B</span><span class="crayon-sy">:</span><span class="crayon-sy">~</span><span class="crayon-sy">$</span><span class="crayon-h"> </span><span class="crayon-e">sudo </span><span class="crayon-i">apt</span>-<span class="crayon-i">get</span><span class="crayon-h"> </span>-<span class="crayon-i">y</span><span class="crayon-h"> </span><span class="crayon-e">install </span><span class="crayon-i">docker</span><span class="crayon-sy">.</span><span class="crayon-e">io</span></div><div class="crayon-line crayon-striped-line" id="crayon-69432b7200b54080427848-2"><span class="crayon-e">Reading </span><span class="crayon-t">package</span><span class="crayon-h"> </span><span class="crayon-i">lists</span><span class="crayon-sy">.</span><span class="crayon-sy">.</span><span class="crayon-sy">.</span><span class="crayon-h"> </span><span class="crayon-e">Done</span></div><div class="crayon-line" id="crayon-69432b7200b54080427848-3"><span class="crayon-e">Building </span><span class="crayon-e">dependency </span><span class="crayon-e">tree </span></div><div class="crayon-line crayon-striped-line" id="crayon-69432b7200b54080427848-4"><span class="crayon-e">Reading </span><span class="crayon-e">state </span><span class="crayon-i">information</span><span class="crayon-sy">.</span><span class="crayon-sy">.</span><span class="crayon-sy">.</span><span class="crayon-h"> </span><span class="crayon-e">Done</span></div><div class="crayon-line" id="crayon-69432b7200b54080427848-5"><span class="crayon-e">The </span><span class="crayon-e">following </span><span class="crayon-e">packages </span><span class="crayon-e">were </span><span class="crayon-e">automatically </span><span class="crayon-e">installed </span><span class="crayon-st">and</span><span class="crayon-h"> </span><span class="crayon-e">are </span><span class="crayon-e">no </span><span class="crayon-e">longer </span><span class="crayon-i">required</span><span class="crayon-sy">:</span></div><div class="crayon-line crayon-striped-line" id="crayon-69432b7200b54080427848-6"><span class="crayon-h"> </span><span class="crayon-i">fonts</span>-<span class="crayon-i">sil</span>-<span class="crayon-e">gentium </span><span class="crayon-i">fonts</span>-<span class="crayon-i">sil</span>-<span class="crayon-i">gentium</span>-<span class="crayon-e">basic </span><span class="crayon-i">fonts</span>-<span class="crayon-e">stix </span><span class="crayon-i">libabw</span>-<span class="crayon-cn">0.1</span>-<span class="crayon-cn">1v5</span><span class="crayon-h"> </span><span class="crayon-i">libcdr</span>-<span class="crayon-cn">0.1</span>-<span class="crayon-cn">1</span><span class="crayon-h"> </span><span class="crayon-i">libcmis</span>-<span class="crayon-cn">0.5</span>-<span class="crayon-cn">5v5</span><span class="crayon-h"> </span><span class="crayon-i">libe</span>-<span class="crayon-i">book</span>-<span class="crayon-cn">0.1</span>-<span class="crayon-cn">1</span><span class="crayon-h"> </span><span class="crayon-e">libeot0 </span><span class="crayon-i">libetonyek</span>-<span class="crayon-cn">0.1</span>-<span class="crayon-cn">1</span><span class="crayon-h"> </span><span class="crayon-i">libfreehand</span>-<span class="crayon-cn">0.1</span>-<span class="crayon-cn">1</span></div><div class="crayon-line" id="crayon-69432b7200b54080427848-7"><span class="crayon-h"> </span><span class="crayon-i">libglew1</span><span class="crayon-sy">.</span><span class="crayon-cn">13</span><span class="crayon-h"> </span><span class="crayon-i">libhsqldb1</span><span class="crayon-sy">.</span><span class="crayon-cn">8.0</span>-<span class="crayon-e">java </span><span class="crayon-i">libmspub</span>-<span class="crayon-cn">0.1</span>-<span class="crayon-cn">1</span><span class="crayon-h"> </span><span class="crayon-i">libmwaw</span>-<span class="crayon-cn">0.3</span>-<span class="crayon-cn">3</span><span class="crayon-h"> </span><span class="crayon-i">libodfgen</span>-<span class="crayon-cn">0.1</span>-<span class="crayon-cn">1</span><span class="crayon-h"> </span><span class="crayon-i">liborcus</span>-<span class="crayon-cn">0.10</span>-<span class="crayon-cn">0v5</span><span class="crayon-h"> </span><span class="crayon-i">libpagemaker</span>-<span class="crayon-cn">0.0</span>-<span class="crayon-cn">0</span><span class="crayon-h"> </span><span class="crayon-i">libreoffice</span>-<span class="crayon-i">sdbc</span>-<span class="crayon-e">firebird </span><span class="crayon-i">librevenge</span>-<span class="crayon-cn">0.0</span>-<span class="crayon-cn">0</span></div><div class="crayon-line crayon-striped-line" id="crayon-69432b7200b54080427848-8"><span class="crayon-h"> </span><span class="crayon-i">libservlet3</span><span class="crayon-sy">.</span><span class="crayon-cn">1</span>-<span class="crayon-e">java </span><span class="crayon-i">libvisio</span>-<span class="crayon-cn">0.1</span>-<span class="crayon-cn">1</span><span class="crayon-h"> </span><span class="crayon-i">libwpd</span>-<span class="crayon-cn">0.10</span>-<span class="crayon-cn">10</span><span class="crayon-h"> </span><span class="crayon-i">libwpg</span>-<span class="crayon-cn">0.3</span>-<span class="crayon-cn">3</span><span class="crayon-h"> </span><span class="crayon-i">libwps</span>-<span class="crayon-cn">0.4</span>-<span class="crayon-cn">4</span><span class="crayon-h"> </span><span class="crayon-i">linux</span>-<span class="crayon-i">headers</span>-<span class="crayon-cn">4.4.0</span>-<span class="crayon-cn">62</span><span class="crayon-h"> </span><span class="crayon-i">linux</span>-<span class="crayon-i">headers</span>-<span class="crayon-cn">4.4.0</span>-<span class="crayon-cn">62</span>-<span class="crayon-e">generic </span><span class="crayon-i">linux</span>-<span class="crayon-i">image</span>-<span class="crayon-cn">4.4.0</span>-<span class="crayon-cn">62</span>-<span class="crayon-e">generic</span></div><div class="crayon-line" id="crayon-69432b7200b54080427848-9"><span class="crayon-e"> </span><span class="crayon-i">linux</span>-<span class="crayon-i">image</span>-<span class="crayon-i">extra</span>-<span class="crayon-cn">4.4.0</span>-<span class="crayon-cn">62</span>-<span class="crayon-e">generic </span><span class="crayon-i">linux</span>-<span class="crayon-t">signed</span>-<span class="crayon-i">image</span>-<span class="crayon-cn">4.4.0</span>-<span class="crayon-cn">62</span>-<span class="crayon-e">generic </span><span class="crayon-i">lp</span>-<span class="crayon-e">solve</span></div><div class="crayon-line crayon-striped-line" id="crayon-69432b7200b54080427848-10"><span class="crayon-st">Use</span><span class="crayon-h"> </span><span class="crayon-s">'sudo apt autoremove'</span><span class="crayon-h"> </span><span class="crayon-st">to</span><span class="crayon-h"> </span><span class="crayon-e">remove </span><span class="crayon-i">them</span><span class="crayon-sy">.</span></div><div class="crayon-line" id="crayon-69432b7200b54080427848-11"><span class="crayon-e">The </span><span class="crayon-e">following </span><span class="crayon-e">additional </span><span class="crayon-e">packages </span><span class="crayon-e">will </span><span class="crayon-e">be </span><span class="crayon-i">installed</span><span class="crayon-sy">:</span></div><div class="crayon-line crayon-striped-line" id="crayon-69432b7200b54080427848-12"><span class="crayon-h"> </span><span class="crayon-i">cgroupfs</span>-<span class="crayon-e">mount </span><span class="crayon-e">containerd </span><span class="crayon-e">runc </span><span class="crayon-i">ubuntu</span>-<span class="crayon-i">fan</span></div><div class="crayon-line" id="crayon-69432b7200b54080427848-13"><span class="crayon-sy">.</span><span class="crayon-sy">.</span><span class="crayon-sy">.</span></div><div class="crayon-line crayon-striped-line" id="crayon-69432b7200b54080427848-14"><span class="crayon-sy">.</span><span class="crayon-sy">.</span><span class="crayon-sy">.</span></div><div class="crayon-line" id="crayon-69432b7200b54080427848-15"> </div><div class="crayon-line crayon-striped-line" id="crayon-69432b7200b54080427848-16"><span class="crayon-e">Setting </span><span class="crayon-e">up </span><span class="crayon-i">docker</span><span class="crayon-sy">.</span><span class="crayon-e">io</span><span class="crayon-h"> </span><span class="crayon-sy">(</span><span class="crayon-cn">1.12.6</span>-<span class="crayon-cn">0ubuntu1</span><span class="crayon-sy">~</span><span class="crayon-cn">16.04.1</span><span class="crayon-sy">)</span><span class="crayon-h"> </span><span class="crayon-sy">.</span><span class="crayon-sy">.</span><span class="crayon-sy">.</span></div><div class="crayon-line" id="crayon-69432b7200b54080427848-17"><span class="crayon-e">Adding </span><span class="crayon-i">group</span><span class="crayon-h"> </span><span class="crayon-sy">docker' (GID 131) ...
3) To verify the installation, use “sudo docker run hello-world”
<div id="crayon-69432b7200b5b617488625" class="crayon-syntax crayon-theme-powershell crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
<div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-copy-button" title="Copy"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div></div></div>
<div class="crayon-info" style="min-height: 18px !important; line-height: 18px !important;"></div>
<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">
falcon@falcon-Satellite-L50D-B:~$ sudo docker run hello-world Unable to find image ‘hello-world:latest’ locally latest: Pulling from library/hello-world 78445dd45222: Pull complete Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7 Status: Downloaded newer image for hello-world:latest
Hello from Docker! This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
- The Docker client contacted the Docker daemon.
- The Docker daemon pulled the “hello-world” image from the Docker Hub.
- The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
- The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID: https://cloud.docker.com/
For more examples and ideas, visit: https://docs.docker.com/engine/userguide/
falcon@falcon-Satellite-L50D-B:~$
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | falcon@falcon-Satellite-L50D-B:~$ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 78445dd45222: Pull complete Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://cloud.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/ falcon@falcon-Satellite-L50D-B:~$ |
4) To get more details about how to use the docker command use “docker –help”
<div id="crayon-69432b7200b5e588975680" class="crayon-syntax crayon-theme-powershell crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
<div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-copy-button" title="Copy"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div></div></div>
<div class="crayon-info" style="min-height: 18px !important; line-height: 18px !important;"></div>
<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">
~$ docker –help Usage: docker [OPTIONS] COMMAND [arg…] docker [ –help | -v | –version ]
A self-sufficient runtime for containers.
Options:
–config=~/.docker Location of client config files -D, –debug Enable debug mode -H, –host=[] Daemon socket(s) to connect to -h, –help Print usage -l, –log-level=info Set the logging level –tls Use TLS; implied by –tlsverify –tlscacert=~/.docker/ca.pem Trust certs signed only by this CA –tlscert=~/.docker/cert.pem Path to TLS certificate file –tlskey=~/.docker/key.pem Path to TLS key file –tlsverify Use TLS and verify the remote -v, –version Print version information and quit
Commands: attach Attach to a running container build Build an image from a Dockerfile commit Create a new image from a container’s changes cp Copy files/folders between a container and the local filesystem … …
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ~$ docker –help Usage: docker [OPTIONS] COMMAND [arg...] docker [ –help | -v | –version ] A self-sufficient runtime for containers. Options: –config=~/.docker Location of client config files -D, –debug Enable debug mode -H, –host=[] Daemon socket(s) to connect to -h, –help Print usage -l, –log-level=info Set the logging level –tls Use TLS; implied by –tlsverify –tlscacert=~/.docker/ca.pem Trust certs signed only by this CA –tlscert=~/.docker/cert.pem Path to TLS certificate file –tlskey=~/.docker/key.pem Path to TLS key file –tlsverify Use TLS and verify the remote -v, –version Print version information and quit Commands: attach Attach to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem ... ... |
To get the help screen about a specific Docker command, use “docker <command> –help”
Example :
<div id="crayon-69432b7200b60079818765" class="crayon-syntax crayon-theme-powershell crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
<div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-copy-button" title="Copy"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div></div></div>
<div class="crayon-info" style="min-height: 18px !important; line-height: 18px !important;"></div>
<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">
~$ docker build –help
Usage: docker build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
Options: –build-arg value Set build-time variables (default []) –cgroup-parent string Optional parent cgroup for the container
1 2 3 4 5 6 7 8 9 | ~$ docker build –help Usage: docker build [OPTIONS] PATH | URL | - Build an image from a Dockerfile Options: –build-arg value Set build-time variables (default []) –cgroup-parent string Optional parent cgroup for the container |
To get the version information use “docker version” command.
<div id="crayon-69432b7200b62768363297" class="crayon-syntax crayon-theme-powershell crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
<div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-copy-button" title="Copy"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div></div></div>
<div class="crayon-info" style="min-height: 18px !important; line-height: 18px !important;"></div>
<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">
~/temp$ sudo docker version Client: Version: 1.12.6 API version: 1.24 Go version: go1.6.2 Git commit: 78d1802 Built: Tue Jan 31 23:35:14 2017 OS/Arch: linux/amd64
Server: Version: 1.12.6 API version: 1.24 Go version: go1.6.2 Git commit: 78d1802 Built: Tue Jan 31 23:35:14 2017 OS/Arch: linux/amd64
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ~/temp$ sudo docker version Client: Version: 1.12.6 API version: 1.24 Go version: go1.6.2 Git commit: 78d1802 Built: Tue Jan 31 23:35:14 2017 OS/Arch: linux/amd64 Server: Version: 1.12.6 API version: 1.24 Go version: go1.6.2 Git commit: 78d1802 Built: Tue Jan 31 23:35:14 2017 OS/Arch: linux/amd64 |
Using Docker Images
We can find out which images are available at our environment using the command given below.
docker images
As Docker command requires root privilege, run it with sudo.
<div id="crayon-69432b7200b63994373253" class="crayon-syntax crayon-theme-powershell crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
<div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-copy-button" title="Copy"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div></div></div>
<div class="crayon-info" style="min-height: 18px !important; line-height: 18px !important;"></div>
<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">
~$ sudo docker images
[sudo] password for falcon:
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 48b5124b2768 4 months ago 1.84 kB
1 2 3 4 | ~$ sudo docker images [sudo] password for falcon: REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest 48b5124b2768 4 months ago 1.84 kB |
The columns of the output for docker images command are :
REPOSITORY – name of repository as existing in docker hub
TAG – tag of the image (could indicate different versions) – can help backwards compatibility testing of app
IMAGE ID – unique 64 hex digit string of chars – simplified to first 12 chars
CREATED – when created
SIZE – how much virtual size
Searching images at Docker Hub
We can look for available docker images at Docker Hub using the “docker search” command. (of course, start with sudo so as to run it with root privilege)
<div id="crayon-69432b7200b65636097648" class="crayon-syntax crayon-theme-powershell crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
<div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-copy-button" title="Copy"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div></div></div>
<div class="crayon-info" style="min-height: 18px !important; line-height: 18px !important;"></div>
<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">
$ sudo docker search ubuntu
[sudo] password for falcon:
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux operating s… 6104 [OK]
rastasheep/ubuntu-sshd Dockerized SSH service, built on top of of… 89 [OK]
ubuntu-upstart Upstart is an event-based replacement for … 74 [OK]
ubuntu-debootstrap debootstrap –variant=minbase –components… 30 [OK]
torusware/speedus-ubuntu Always updated official Ubuntu docker imag… 28 [OK]
nuagebec/ubuntu Simple always updated Ubuntu docker images… 21 [OK]
nickistre/ubuntu-lamp LAMP server on Ubuntu 19 [OK]
solita/ubuntu-systemd Ubuntu + systemd 8 [OK]
nimmis/ubuntu This is a docker images different LTS vers… 7 [OK]
darksheer/ubuntu Base Ubuntu Image – Updated hourly 3 [OK]
jordi/ubuntu Ubuntu Base Image 1 [OK]
webhippie/ubuntu Docker images for ubuntu 1 [OK]
vcatechnology/ubuntu A Ubuntu image that is updated daily 1 [OK]
admiringworm/ubuntu Base ubuntu images based on the official u… 1 [OK]
labengine/ubuntu Images base ubuntu 0 [OK]
konstruktoid/ubuntu Ubuntu base image 0 [OK]
datenbetrieb/ubuntu custom flavor of the official ubuntu base … 0 [OK]
forumi0721ubuntux64/ubuntu-x64-dev ubuntu-x64-dev 0 [OK]
lynxtp/ubuntu https://github.com/lynxtp/docker-ubuntu 0 [OK]
forumi0721ubuntuarmhf/ubuntu-armhf-dev ubuntu-armhf-dev 0 [OK]
forumi0721ubuntuaarch64/ubuntu-aarch64-dev ubuntu-aarch64-dev 0 [OK]
teamrock/ubuntu TeamRock’s Ubuntu image configured with AW… 0 [OK]
smartentry/ubuntu ubuntu with smartentry 0 [OK]
esycat/ubuntu Ubuntu LTS 0 [OK]
forumi0721ubuntux64/ubuntu-x64-dev-armbian ubuntu-x64-dev-armbian 0 [OK]
falcon@falcon-Satellite-L50D-B:~$
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | $ sudo docker search ubuntu [sudo] password for falcon: NAME DESCRIPTION STARS OFFICIAL AUTOMATED ubuntu Ubuntu is a Debian-based Linux operating s... 6104 [OK] rastasheep/ubuntu-sshd Dockerized SSH service, built on top of of... 89 [OK] ubuntu-upstart Upstart is an event-based replacement for ... 74 [OK] ubuntu-debootstrap debootstrap –variant=minbase –components... 30 [OK] torusware/speedus-ubuntu Always updated official Ubuntu docker imag... 28 [OK] nuagebec/ubuntu Simple always updated Ubuntu docker images... 21 [OK] nickistre/ubuntu-lamp LAMP server on Ubuntu 19 [OK] solita/ubuntu-systemd Ubuntu + systemd 8 [OK] nimmis/ubuntu This is a docker images different LTS vers... 7 [OK] darksheer/ubuntu Base Ubuntu Image – Updated hourly 3 [OK] jordi/ubuntu Ubuntu Base Image 1 [OK] webhippie/ubuntu Docker images for ubuntu 1 [OK] vcatechnology/ubuntu A Ubuntu image that is updated daily 1 [OK] admiringworm/ubuntu Base ubuntu images based on the official u... 1 [OK] labengine/ubuntu Images base ubuntu 0 [OK] konstruktoid/ubuntu Ubuntu base image 0 [OK] datenbetrieb/ubuntu custom flavor of the official ubuntu base ... 0 [OK] forumi0721ubuntux64/ubuntu-x64-dev ubuntu-x64-dev 0 [OK] lynxtp/ubuntu https://github.com/lynxtp/docker-ubuntu 0 [OK] forumi0721ubuntuarmhf/ubuntu-armhf-dev ubuntu-armhf-dev 0 [OK] forumi0721ubuntuaarch64/ubuntu-aarch64-dev ubuntu-aarch64-dev 0 [OK] teamrock/ubuntu TeamRock's Ubuntu image configured with AW... 0 [OK] smartentry/ubuntu ubuntu with smartentry 0 [OK] esycat/ubuntu Ubuntu LTS 0 [OK] forumi0721ubuntux64/ubuntu-x64-dev-armbian ubuntu-x64-dev-armbian 0 [OK] falcon@falcon-Satellite-L50D-B:~$ |
We can see the name of the repository, a reduced description, how many people have starred it as being something they think is a good repository, whether it’s an official repository (which means that it’s been approved by the Docker team), as well as whether it’s an automated build.
An automated build is a Docker image that builds automatically when a Git repository that it is linked to is updated. The code gets updated, a web hook gets called, and a new Docker image is built in the Docker Hub.
To pull an image from Docker Hub, use :
docker pull <image name>
Example:
docker pull tutum/ubuntu
After pulling, we can display the list of images that we have currently using “docker images” command.
<div id="crayon-69432b7200b67178158242" class="crayon-syntax crayon-theme-powershell crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
<div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-copy-button" title="Copy"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div></div></div>
<div class="crayon-info" style="min-height: 18px !important; line-height: 18px !important;"></div>
<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">
~$ sudo docker pull nimmis/ubuntu Using default tag: latest latest: Pulling from nimmis/ubuntu bd97b43c27e3: Pull complete 6960dc1aba18: Pull complete 2b61829b0db5: Pull complete 1f88dc826b14: Pull complete 73b3859b1e43: Pull complete 06256784393b: Pull complete 8b3f317c599d: Pull complete Digest: sha256:5607642f02113fa3247290ade1b397892a07aab52e27babb5a436752c5c21a19 Status: Downloaded newer image for nimmis/ubuntu:latest
1 2 3 4 5 6 7 8 9 10 11 12 | ~$ sudo docker pull nimmis/ubuntu Using default tag: latest latest: Pulling from nimmis/ubuntu bd97b43c27e3: Pull complete 6960dc1aba18: Pull complete 2b61829b0db5: Pull complete 1f88dc826b14: Pull complete 73b3859b1e43: Pull complete 06256784393b: Pull complete 8b3f317c599d: Pull complete Digest: sha256:5607642f02113fa3247290ade1b397892a07aab52e27babb5a436752c5c21a19 Status: Downloaded newer image for nimmis/ubuntu:latest |
Running the images
Let’s look at how to get images up and running and turned into containers.
The most basic way to run a container is as follows:
docker run -i -t <image_name>:<tag> /bin/bash
Example:
<div id="crayon-69432b7200b6a062826545" class="crayon-syntax crayon-theme-powershell crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
<div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-copy-button" title="Copy"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div></div></div>
<div class="crayon-info" style="min-height: 18px !important; line-height: 18px !important;"></div>
<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">
$ sudo docker run –i –t nginx:latest /bin/bash
1 | $ sudo docker run –i –t nginx:latest /bin/bash |
We start off with the docker run command, followed by two options, -i and -t .
The first -i option, gives us an interactive shell into the running container. The second -t option will allocate a pseudo tty, which when using interactive processes, must be used together with the -i switch. You can also use switches together; for example, -it is commonly used for these two switches. This will help you test out the container to see how it operates before running it as a daemon.
Once you are comfortable with your container, you can test how it operates in daemon mode:
docker run -d <image_name>:<tag>
We can see the container ID, the image name on which the container is based, the command that is running to keep the image alive, when the container started up, its current status, a listing of any exposed network ports, as well as the name given to the container. Now, these names are random unless otherwise specified by the –name= switch.
You can also expose ports on your containers using the -p switch, just like this:
$ docker run -d -p <host_port>:<container_port> <image>:<tag>
<div id="crayon-69432b7200b6c352906631" class="crayon-syntax crayon-theme-powershell crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
<div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-copy-button" title="Copy"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div></div></div>
<div class="crayon-info" style="min-height: 18px !important; line-height: 18px !important;"></div>
<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">
$ sudo docker run -d -p 8080:80 ubuntu:14.10
1 | $ sudo docker run -d -p 8080:80 ubuntu:14.10 |
In the next part of this series we will discuss about how to manipulate Docker images in detail.
Docker Base Image
- Docker containers are created using images.
- An image can be basic, with nothing but the operating system core or it can consist of a sophisticated pre-built application stack ready for launch.
- A base image is the one without any further layers below. This is the most basic form of a Docker image that has just the operating system.
- The Docker Hub has base images for all of the major Linux distros. But you are also free to create your own base image.
- You can use the scratch repository in the Docker hub. Use “FROM scratch” in Dockerfile. Alternatively the tar command can be used.
Dockerfile
A Dockerfile is a script composed of various commands (instructions) and arguments listed one after another. This will automatically perform actions on the base image in order to create a new one.
- A base Docker image doesn’t require many Dockerfile instructions
- If we add more and more layers to the base image, we will need to know more about Dockerfile instructions
How to create Dockerfile ?
1) List the instructions one after another in a plain text file
2) Run “docker build” command in the same directory
3) Image gets created
Dockerfile consists of :
1) comments (starting with #)
2) commands (with arguments) starting with an instruction (in CAPS)
Note : A dockerfile should always start with “FROM” instruction (indicates base image)
Important Dockerfile Instructions
1) ADD – copies files from source (on the host) into the container’s own file system at the set destination.
Example
#ADD src dest
<div id="crayon-69432b7200b6d222724692" class="crayon-syntax crayon-theme-powershell crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
<div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-copy-button" title="Copy"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div></div></div>
<div class="crayon-info" style="min-height: 18px !important; line-height: 18px !important;"></div>
<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">
ADD /source_path /docker_container_dest_path
1 | ADD /source_path /docker_container_dest_path |
2) ENV – This is used for setting one or more environment variables
Example
#ENV variable value
<div id="crayon-69432b7200b6f296267589" class="crayon-syntax crayon-theme-powershell crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
<div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-copy-button" title="Copy"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div></div></div>
<div class="crayon-info" style="min-height: 18px !important; line-height: 18px !important;"></div>
<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">
ENV Answer 1
1 | ENV Answer 1 |
3) FROM – defines the base image to be used for the build process. It can be any image from Docker Hub or the images you have created previously. This should be the first instruction in the Dockerfile.
Example
<div id="crayon-69432b7200b70670923894" class="crayon-syntax crayon-theme-powershell crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
<div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-copy-button" title="Copy"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div></div></div>
<div class="crayon-info" style="min-height: 18px !important; line-height: 18px !important;"></div>
<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">
#FROM image_name FROM ubuntu
1 2 | #FROM image_name FROM ubuntu |
4) RUN – Indicates the central executing directive for Dockerfile. This instruction takes a command as its argument and runs it to create the image. The run command executes in the shell which is usually “/bin/sh -c”. To run more than one command, append “\” and continue on the next line.
Example
<div id="crayon-69432b7200b72092802395" class="crayon-syntax crayon-theme-powershell crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
<div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-copy-button" title="Copy"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div></div></div>
<div class="crayon-info" style="min-height: 18px !important; line-height: 18px !important;"></div>
<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">
#RUN usage RUN apt-get update && apt-get install -y ruby ruby-dev
1 2 | #RUN usage RUN apt-get update && apt-get install -y ruby ruby-dev |
5) EXPOSE – associates a specified port to enable networking between the running process inside the container and the outside (e.g. the host).
Example
<div id="crayon-69432b7200b73116577131" class="crayon-syntax crayon-theme-powershell crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
<div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-copy-button" title="Copy"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div></div></div>
<div class="crayon-info" style="min-height: 18px !important; line-height: 18px !important;"></div>
<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">
#EXPOSE port_number EXPOSE 8090
1 2 | #EXPOSE port_number EXPOSE 8090 |
6) VOLUME – For enabling access from a container to a directory on the host machine (mounting).
Example
<div id="crayon-69432b7200b75880429080" class="crayon-syntax crayon-theme-powershell crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
<div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-copy-button" title="Copy"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div></div></div>
<div class="crayon-info" style="min-height: 18px !important; line-height: 18px !important;"></div>
<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">
#VOLUME usage VOLUME [“/var/www”, “/var/log/apache2”]
1 2 | #VOLUME usage VOLUME [“/var/www”, “/var/log/apache2”] |
7) MAINTAINER – This is a non-executing command, for declaring the author of the Dockerfile. This is not mandatory, but recommended.
Example
<div id="crayon-69432b7200b76287373286" class="crayon-syntax crayon-theme-powershell crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
<div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-copy-button" title="Copy"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div></div></div>
<div class="crayon-info" style="min-height: 18px !important; line-height: 18px !important;"></div>
<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">
#MAINTAINER name MAINTAINER Tom <tommcdonald@abc.com>
1 2 | #MAINTAINER name MAINTAINER Tom <tommcdonald@abc.com> |
8) WORKDIR – Specifies working directory
Example
<div id="crayon-69432b7200b77375302842" class="crayon-syntax crayon-theme-powershell crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
<div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-copy-button" title="Copy"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div></div></div>
<div class="crayon-info" style="min-height: 18px !important; line-height: 18px !important;"></div>
<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">
WORKDIR /opt/src/app
1 | WORKDIR /opt/src/app |
9) ENTRYPOINT – Used for configuring an executable container
Example
<div id="crayon-69432b7200b79137008080" class="crayon-syntax crayon-theme-powershell crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
<div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-copy-button" title="Copy"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div></div></div>
<div class="crayon-info" style="min-height: 18px !important; line-height: 18px !important;"></div>
<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">
ENTRYPOINT [“abcontainer1”]
1 | ENTRYPOINT [“abcontainer1”] |
How to build and run the Dockerfile
1) Navigate to the folder where the Dockerfile is available and use the “sudo docker build” command. This will create the image.
2) Verify the image using “sudo docker images”
3) Run the image to create a container using “sudo docker run”
