{"id":5502,"date":"2015-12-29T20:29:47","date_gmt":"2015-12-29T12:29:47","guid":{"rendered":"http:\/\/rmohan.com\/?p=5502"},"modified":"2015-12-29T20:30:32","modified_gmt":"2015-12-29T12:30:32","slug":"docker-2","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=5502","title":{"rendered":"DOCKER"},"content":{"rendered":"<p>Docker is an open platform for Sys Admins and developers to build, ship and run distributed applications. Applications are easy and quickly assembled from reusable and portable components, eliminating the silo-ed approach between development, QA, and production environments.<\/p>\n<p>Individual components can be microservices coordinated by a program that contains the business process logic (an evolution of SOA, or Service Oriented Architecture). They can be deployed independently and scaled horizontally as needed, so the project benefits from flexibility and efficient operations. This is of great help in DevOps.<\/p>\n<p><a href=\"http:\/\/rmohan.com\/wp-content\/uploads\/2015\/12\/docker-001.jpg\" rel=\"attachment wp-att-5503\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5503\" src=\"http:\/\/rmohan.com\/wp-content\/uploads\/2015\/12\/docker-001.jpg\" alt=\"docker 001\" width=\"400\" height=\"322\" srcset=\"https:\/\/mohan.sg\/wp-content\/uploads\/2015\/12\/docker-001.jpg 400w, https:\/\/mohan.sg\/wp-content\/uploads\/2015\/12\/docker-001-300x242.jpg 300w, https:\/\/mohan.sg\/wp-content\/uploads\/2015\/12\/docker-001-150x121.jpg 150w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>At a high-level, Docker is built of:<\/p>\n<p>&#8211; Docker Engine: a portable and lightweight, runtime and packaging tool<\/p>\n<p>&#8211; Docker Hub: a cloud service for sharing applications and automating workflows<\/p>\n<p>There are more components (Machine, Swarm) but that&#8217;s beyond the basic overview I&#8217;m giving here.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Containers are lightweight, portable, isolated, self-sufficient &#8220;slices of a server&#8221; that contain any application (often they contain microservices).<\/p>\n<p>They deliver on full DevOps goal:<\/p>\n<p>&#8211; Build once\u2026 run anywhere (Dev, QA, Prod, DR).<\/p>\n<p>&#8211; Configure once\u2026 run anything (any container).<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Docker Features <\/strong><\/p>\n<ul>\n<li>Multi-arch, multi-OS ? Stable control API ? Stable plugin API ? Resiliency ? Signature ? Clustering<\/li>\n<\/ul>\n<p>Docker: ? Is easy to install ? Will run anything, anywhere ? Gives you repeatable builds<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Deploy efficiently<\/strong><\/p>\n<ul>\n<li>Containers are lightweight \u2013 Typical laptop runs 10-100 containers easily<\/li>\n<\/ul>\n<p>\u2013 Typical server can run 100-1000 containers<\/p>\n<ul>\n<li>Containers can run at native speeds<\/li>\n<li><a href=\"http:\/\/rmohan.com\/wp-content\/uploads\/2015\/12\/docker-002.jpg\" rel=\"attachment wp-att-5504\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5504\" src=\"http:\/\/rmohan.com\/wp-content\/uploads\/2015\/12\/docker-002.jpg\" alt=\"docker 002\" width=\"745\" height=\"451\" srcset=\"https:\/\/mohan.sg\/wp-content\/uploads\/2015\/12\/docker-002.jpg 745w, https:\/\/mohan.sg\/wp-content\/uploads\/2015\/12\/docker-002-300x182.jpg 300w, https:\/\/mohan.sg\/wp-content\/uploads\/2015\/12\/docker-002-150x91.jpg 150w, https:\/\/mohan.sg\/wp-content\/uploads\/2015\/12\/docker-002-400x242.jpg 400w\" sizes=\"(max-width: 745px) 100vw, 745px\" \/><\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>High level approach<\/strong><\/p>\n<p>it&#8217;s a lightweight VM ? own process space ? own network interface ? can run stuff as root ? can have its own \/sbin\/init (different from the host)<\/p>\n<p>How does it work?<\/p>\n<p>Isolation with namespaces ? pid ? mnt ? net ? uts ? ipc ? user<\/p>\n<p>&nbsp;<\/p>\n<p>docker run -i -t \\<\/p>\n<p>\\<\/p>\n<p>&#8211;net=none \\<\/p>\n<p>&#8211;lxc-conf=&#8217;lxc.network.type=veth&#8217; \\<\/p>\n<p>&#8211;lxc-conf=&#8217;lxc.network.ipv4=172.16.21.112\/16&#8242; \\<\/p>\n<p>&#8211;lxc-conf=&#8217;lxc.network.ipv4.gateway=172.16.255.254&#8242; \\<\/p>\n<p>&#8211;lxc-conf=&#8221;lxc.network.link=br0&#8243; \\<\/p>\n<p>&#8211;lxc-conf=&#8217;lxc.network.name=eth0&#8242; \\<\/p>\n<p>&#8211;lxc-conf=&#8217;lxc.network.flags=up&#8217; \\<\/p>\n<p>&nbsp;<\/p>\n<p># docker attach [CONTAINER ID]\u00a0# ps axufwwUSER\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PID %CPU %MEM\u00a0\u00a0 VSZ\u00a0\u00a0 RSS TTY\u00a0\u00a0\u00a0\u00a0 STAT START\u00a0\u00a0 TIME COMMANDroot\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1 0.0 0.0 14728 1900 ?\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 S \u00a0\u00a0\u00a002:17\u00a0\u00a0 0:00 \/bin\/bashroot\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 83 0.0 0.0 177340 3860 ?\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Ss\u00a0\u00a0 02:20\u00a0\u00a0 0:00 \/usr\/sbin\/httpdapache\u00a0\u00a0\u00a0\u00a0 85 0.0 0.0 177340 2472 ?\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 S\u00a0\u00a0 02:20\u00a0\u00a0 0:00 _ \/usr\/sbin\/httpdapache\u00a0\u00a0\u00a0\u00a0 86 0.0 0.0 177340 2472 ?\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 S\u00a0\u00a0 02:20\u00a0\u00a0 0:00 _ \/usr\/sbin\/httpdapache\u00a0\u00a0\u00a0\u00a0 87 0.0 0.0 177340 2472 ?\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 S\u00a0\u00a0 02:20\u00a0\u00a0 0:00 _ \/usr\/sbin\/httpdapache\u00a0\u00a0\u00a0\u00a0 88 0.0 0.0 177340 2472 ?\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 S\u00a0\u00a0 02:20\u00a0\u00a0 0:00 _ \/usr\/sbin\/httpdapache\u00a0\u00a0\u00a0\u00a0 89 0.0 0.0 177340 2472 ?\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 S\u00a0\u00a0 02:20\u00a0\u00a0 0:00 _ \/usr\/sbin\/httpdapache\u00a0\u00a0\u00a0\u00a0 90 0.0 0.0 177340 2472 ?\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 S\u00a0\u00a0 02:20\u00a0\u00a0 0:00 _ \/usr\/sbin\/httpdapache\u00a0\u00a0\u00a0\u00a0 91 0.0 0.0 177340 2472 ?\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 S\u00a0\u00a0 02:20\u00a0\u00a0 0:00 _ \/usr\/sbin\/httpdapache\u00a0\u00a0\u00a0\u00a0 92 0.0 0.0 177340 2472 ?\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 S\u00a0\u00a0 02:20\u00a0\u00a0 0:00 _ \/usr\/sbin\/httpdroot\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 93 0.0 0.0 16624 1068 ?\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 R+\u00a0\u00a0 02:20\u00a0\u00a0 0:00 ps axufww\u00a0# ifconfigeth0\u00a0\u00a0\u00a0\u00a0 Link encap:Ethernet HWaddr &#8230;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 inet addr:172.16.21.112 Bcast:172.16.255.255 Mask:255.255.0.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 inet6 addr: fe80::a46d:79ff:fe20:ea7e\/64 Scope:Link\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 RX packets:1668 errors:0 dropped:0 overruns:0 frame:0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 TX packets:6 errors:0 dropped:0 overruns:0 carrier:0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 collisions:0 txqueuelen:1000\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 RX bytes:222716 (217.4 KiB) TX bytes:468 (468.0 b)\u00a0lo\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Link encap:Local Loopback\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 inet addr:127.0.0.1 Mask:255.0.0.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 inet6 addr: ::1\/128 Scope:Host\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 UP LOOPBACK RUNNING MTU:65536 Metric:1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 RX packets:0 errors:0 dropped:0 overruns:0 frame:0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 collisions:0 txqueuelen:0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)<\/p>\n<p>&nbsp;<\/p>\n<p># docker psCONTAINER ID\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 IMAGE\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 COMMAND\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 CREATED\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 STATUS\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PORTS\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 NAMES7baceac4e139\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 mohan\/centos6:latest\u00a0\u00a0 &#8220;\/bin\/bash&#8221;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 25 seconds ago\u00a0\u00a0\u00a0\u00a0 Up 25 seconds\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 8a6311dbdbb0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 mohan\/centos6:latest\u00a0\u00a0 &#8220;\/bin\/bash&#8221;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 About an hour ago\u00a0\u00a0 Up About an hour<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Compute efficiency<\/strong><\/p>\n<p>Almost no overhead ? processes are isolated, but run straight on the host ? CPU performance = native performance ? memory performance = a few % shaved off for (optional) accounting ? network performance = small overhead; can be reduced to zero<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Docker can help Developer<\/strong><\/p>\n<p><a href=\"http:\/\/rmohan.com\/wp-content\/uploads\/2015\/12\/docker-003.jpg\" rel=\"attachment wp-att-5506\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5506\" src=\"http:\/\/rmohan.com\/wp-content\/uploads\/2015\/12\/docker-003.jpg\" alt=\"docker 003\" width=\"660\" height=\"485\" srcset=\"https:\/\/mohan.sg\/wp-content\/uploads\/2015\/12\/docker-003.jpg 660w, https:\/\/mohan.sg\/wp-content\/uploads\/2015\/12\/docker-003-300x220.jpg 300w, https:\/\/mohan.sg\/wp-content\/uploads\/2015\/12\/docker-003-150x110.jpg 150w, https:\/\/mohan.sg\/wp-content\/uploads\/2015\/12\/docker-003-400x294.jpg 400w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li>inside my container: \u2013 my code \u2013 my libraries \u2013 my package manager \u2013 my app \u2013 my data<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Locking Down and Patching Containers<\/p>\n<p>&nbsp;<\/p>\n<p>A regular system often contains software components that aren\u2019t required by its applications. In contrast, a proper Docker container includes only those dependencies that the application requires, as explicitly prescribed in in the corresponding Dockerfile. This decreases the vulnerability surface of the application\u2019s environment and makes it easier to lock it down. The smaller footprint also decreases the number of components that need to be patched with security updates.<\/p>\n<p>&nbsp;<\/p>\n<p>When patching is needed, the workflow is different from a typical vulnerability management approach:<\/p>\n<p>&nbsp;<\/p>\n<p>Traditionally, security patches are installed on the system independently of the application, in the hopes that the update doesn\u2019t break the app.<\/p>\n<p>Containers integrate the app with dependencies more tightly and allow for the container\u2019s image to be patched as part of the application deployment process.<\/p>\n<p>Rebuilding the container\u2019s image (e.g., \u201cdocker build\u201d) allows the application\u2019s dependencies to be automatically updated.<\/p>\n<p>The container ecosystem changes the work that ops might traditionally perform, but that isn\u2019t necessarily a bad thing.<\/p>\n<p>&nbsp;<\/p>\n<p>Running a vulnerability scanner when distributing patches the traditional way doesn\u2019t quite work in this ecosystem. What a container-friendly approach should entail is still unclear. However, it promises the advantage of requiring fewer updates, bringing dev and ops closer together and defining a clear set of software components that need to be patched or otherwise locked down.<\/p>\n<p>Security Benefits and Weaknesses of Containers<\/p>\n<p>&nbsp;<\/p>\n<p>Application containers offer operational benefits that will continue to drive the development and adoption of the platform. While the use of such technologies introduces risks, it can also provide security benefits:<\/p>\n<p>&nbsp;<\/p>\n<p>Containers make it easier to segregate applications that would traditionally run directly on the same host. For instance, an application running in one container only has access to the ports and files explicitly exposed by other container.<\/p>\n<p>Containers encourage treating application environments as transient, rather static systems that exist for years and accumulate risk-inducing artifacts.<\/p>\n<p>Containers make it easier to control what data and software components are installed through the use of repeatable, scripted instructions in setup files.<\/p>\n<p>Containers offer the potential of more frequent security patching by making it easier to update the environment as part of an application update. They also minimize the effort of validating compatibility between the app and patches.<\/p>\n<p>&nbsp;<\/p>\n<p>Not all is peachy in the world of application containers, of course. The security risks that come to mind when assessing how and whether to use containers include the following:<\/p>\n<p>&nbsp;<\/p>\n<p>The flexibility of containers makes it easy to run multiple instances of applications (container sprawl) and indirectly leads to Docker images that exist at varying security patch levels.<\/p>\n<p>The isolation provided by Docker is not as robust as the segregation established by hypervisors for virtual machines.<\/p>\n<p>The use and management of application containers is not well-understood by the broader ops, infosec, dev and auditors community yet.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Docker is an open platform for Sys Admins and developers to build, ship and run distributed applications. Applications are easy and quickly assembled from reusable and portable components, eliminating the silo-ed approach between development, QA, and production environments.<\/p>\n<p>Individual components can be microservices coordinated by a program that contains the business process logic (an evolution [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5502"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5502"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5502\/revisions"}],"predecessor-version":[{"id":5507,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5502\/revisions\/5507"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5502"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5502"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}