{"id":1956,"date":"2017-08-24T14:50:02","date_gmt":"2017-08-24T19:50:02","guid":{"rendered":"http:\/\/osric.com\/chris\/accidental-developer\/?p=1956"},"modified":"2017-08-24T18:42:45","modified_gmt":"2017-08-24T23:42:45","slug":"running-centos-in-a-docker-container","status":"publish","type":"post","link":"https:\/\/osric.com\/chris\/accidental-developer\/2017\/08\/running-centos-in-a-docker-container\/","title":{"rendered":"Running CentOS in a Docker container"},"content":{"rendered":"<p>I&#8217;m just getting started with Docker. I&#8217;ve thought for years that containerization is a great idea, but I haven&#8217;t actually done anything with containers yet. Time to get started.<\/p>\n<p>I ran through a couple tutorials on the <a href=\"https:\/\/docs.docker.com\/get-started\/\">Docker docs site<\/a> and created a <a href=\"https:\/\/cloud.docker.com\/\">cloud.docker.com<\/a> account to get some basic familiarity.<\/p>\n<p>I found the CentOS container repository on Docker Hub: <a href=\"https:\/\/hub.docker.com\/_\/centos\/\">https:\/\/hub.docker.com\/_\/centos\/<\/a><\/p>\n<p>Let&#8217;s try running it!<\/p>\n<p><code>$ docker pull centos<br \/>\n$ docker run centos<\/code><\/p>\n<p>Did it do anything? It looks like it did something. At least, it didn&#8217;t give me an error. What did it do? How do I access it?<\/p>\n<p><code>$ docker container ls<br \/>\nCONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES<\/code><\/p>\n<p>Nothing is actively running. That makes sense, because we&#8217;re not telling the containerized OS to do anything &#8212; it starts, it doesn&#8217;t have anything to do, and so it shuts down immediately. Instead we can tell it to run interactively and with a terminal by specifying a couple options:<\/p>\n<p><code>-i, --interactive<br \/>\n-t, --tty<\/code> (&#8220;allocate a pseudo-TTY&#8221;, i.e. a terminal)<br \/>\n(see <code>docker run --help<\/code> for details)<\/p>\n<p><code>$ docker run -i -t centos<br \/>\n[root@4f0b435cdbd7 \/]# <\/code><\/p>\n<p>I&#8217;m in! <\/p>\n<p>What if I want to modify the container? Right now it is pretty bare-bones. For example, this doesn&#8217;t even have <code>man<\/code> installed:<\/p>\n<p><code>[root@4f0b435cdbd7 \/]# man man<br \/>\nbash: man: command not found<\/p>\n<p>[root@4f0b435cdbd7 \/]# yum install man<br \/>\n...<br \/>\n[root@4f0b435cdbd7 \/]# man man<br \/>\nNo manual entry for man<\/code><\/p>\n<p>Quite the improvement! Now we need to save our change:<\/p>\n<p><code>[root@4f0b435cdbd7 \/]# exit<\/p>\n<p>$ docker commit 4f0b435cdbd7 man-centos<br \/>\n$ docker run -i -t man-centos<\/p>\n<p>[root@953c512d6707 \/]# man man<br \/>\nNo manual entry for man<\/code><\/p>\n<p>Progress! Now we have a CentOS container where <code>man<\/code> is already installed. Exciting.<\/p>\n<p>I can&#8217;t (that I know of) inspect the container and know whether or not <code>man<\/code> is installed without running it. That&#8217;s fine for many cases, but next I will attempt to figure out how specify via a <a href=\"https:\/\/docs.docker.com\/engine\/reference\/builder\/\">Dockerfile<\/a> that <code>man<\/code> is installed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m complete new to Docker specifically and containers in general, but thought I&#8217;d try running CentOS in a Docker container. There were a couple non-obvious steps involved that I list here.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[451],"tags":[414,450,449],"class_list":["post-1956","post","type-post","status-publish","format-standard","hentry","category-docker","tag-centos","tag-containers","tag-docker"],"_links":{"self":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1956","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/comments?post=1956"}],"version-history":[{"count":5,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1956\/revisions"}],"predecessor-version":[{"id":1972,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1956\/revisions\/1972"}],"wp:attachment":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/media?parent=1956"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/categories?post=1956"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/tags?post=1956"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}