{"id":3105,"date":"2015-05-25T07:52:27","date_gmt":"2015-05-25T07:52:27","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=3105"},"modified":"2015-05-25T07:52:27","modified_gmt":"2015-05-25T07:52:27","slug":"getting-started-with-docker","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/getting-started-with-docker\/","title":{"rendered":"Getting started with Docker"},"content":{"rendered":"<p>I&#8217;ve been wanting to try out Docker for a while. Finally got my Ubuntu 14.04 server up and running, so now&#8217;s the time.<\/p>\n<p>First off I installed docker as per the instruction on <a href=\"http:\/\/www.liquidweb.com\/kb\/how-to-install-docker-on-ubuntu-14-04-lts\/\" title=\"How to Install Docker on Ubuntu 14.04 LTS\" target=\"_blank\">How to Install Docker on Ubuntu 14.04 LTS<\/a>.<\/p>\n<p><strong>What version of Docker am I running?<\/strong><\/p>\n<p>Simple enough, just type <em>docker version<\/em>. Assuming the docker daemon is running you should see various bits of version information.<\/p>\n<p>I&#8217;m currently running Client version 1.0.1<\/p>\n<p><strong>How to search for container images<\/strong><\/p>\n<p>We&#8217;re going to start by simply trying to find an existing images that we can pull onto our server, so typing <em>docker search &lt;name of image&gt;<\/em> will result in a list of images found with a match on the supplied image name.<\/p>\n<p>For example <em>docker search mongodb<\/em> will return a list from the Docker hub of images with <em>mongodb<\/em in the image name.\n\n<strong>Installing an image<\/strong><\/p>\n<p>Once we&#8217;ve found the image we want we need to &#8220;pull&#8221; it onto our machine using <em>docker pull &lt;name of image&gt;<\/em><\/p>\n<p>So let&#8217;s pull down the official mongodb image<\/p>\n<p><em>docker pull mongo<\/em><\/p>\n<p>This command will cause docker to download the current <em>mongo<\/em> image. Once completed you will not need to pull the image again it will be stored locally.<\/p>\n<p><strong>Hold on where are images stored locally?<\/strong><\/p>\n<p>Run <em>docker info<\/em> to see where the root directory for docker is, as well as information on the number of images and containers stored locally.<\/p>\n<p><strong>Runnning a container<\/strong><\/p>\n<p>Once we&#8217;ve pulled down an image we can run and application within the container, for example <em>docker run &lt;name of image&gt; &lt;command to run&gt;<\/em><\/p>\n<p>Let&#8217;s run our mongodb container by typing the following<\/p>\n<ul>\n<li>docker run &#8211;name some-mongo -d mongo<\/li>\n<li>docker run -it &#8211;link some-mongo:mongo &#8211;rm mongo sh -c &#8216;exec mongo &#8220;$MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT&#8221;&#8216;<\/li>\n<\/ul>\n<p>In the above some-mongo should be replaced with the name you want to use.<\/p>\n<p>Note: These command lines will run mongodb in interactive mode, i.e. we will be placed into the mongodb shell.<\/p>\n<p><strong>Updating the container<\/strong><\/p>\n<p>An image itself may be based upon an OS, such as Ubuntu. So we can actually run commands on the operating system in the container, for example apt-get. Installing software into an OS container is cool but we will then want to persist such changes to the container.<\/p>\n<p>Whilst the changes have been made, they are not yet persisted to the containter. To persist our changes we need to commit them.<\/p>\n<p>First we need to find the ID of the container, for example running <em>docker ps -l<\/em>, then we save the changes using <em>docker commit &lt;ID&gt; &lt;new container name&gt;<\/em>. <\/p>\n<p>You needn&#8217;t type the whole ID from the call to docker ps -l, the first three or four characters (assuming they&#8217;re unique) will suffice.<\/p>\n<p>The value returned from the commit is the new image id.<\/p>\n<p><strong>Inspect<\/strong><\/p>\n<p>We can view more extensive information on a container by using <em>docker inspect &lt;ID&gt;<\/em>. Remember the ID can be found using <em>docker ps<\/em>.<\/p>\n<p>Inspect allows is to see all sorts of information including the image&#8217;s IP address.<\/p>\n<p><strong>Pushing an image to the Docker Hub Registry<\/strong><\/p>\n<p>Once we&#8217;re happy with our image we can push it to the docker hub to allow others to share it. Simply use <em>docker push &lt;name of image&gt;<\/em>.<\/p>\n<p>To find the images on your machine simply use <em>docker images<\/em>.<\/p>\n<p><strong>Removing all containers and all images<\/strong><\/p>\n<p>We can use docker&#8217;s ps command along with the <em>docker rm<\/em> command <\/p>\n<p><em>docker rm $(docker ps -a -q)<\/em><\/p>\n<p>to remove all containers and we can use the <em>docker rmi<\/em> command to remove images as follows<\/p>\n<p><em>docker rmi $(docker images -q)<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been wanting to try out Docker for a while. Finally got my Ubuntu 14.04 server up and running, so now&#8217;s the time. First off I installed docker as per the instruction on How to Install Docker on Ubuntu 14.04 LTS. What version of Docker am I running? Simple enough, just type docker version. Assuming [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[102],"tags":[],"class_list":["post-3105","post","type-post","status-publish","format-standard","hentry","category-docker"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/3105","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=3105"}],"version-history":[{"count":14,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/3105\/revisions"}],"predecessor-version":[{"id":3184,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/3105\/revisions\/3184"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=3105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=3105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=3105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}