{"id":262565,"date":"2021-05-28T15:00:00","date_gmt":"2021-05-28T12:00:00","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/what-does-docker-do-and-when-should-you-use-it-cloudsavvy-it\/"},"modified":"2021-05-28T15:00:00","modified_gmt":"2021-05-28T12:00:00","slug":"what-does-docker-do-and-when-should-you-use-it-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/what-does-docker-do-and-when-should-you-use-it-cloudsavvy-it\/","title":{"rendered":"#What Does Docker Do, and When Should You Use It? \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a22f31251036\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a22f31251036\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/what-does-docker-do-and-when-should-you-use-it-cloudsavvy-it\/#What_Is_Docker\" >What Is Docker?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/what-does-docker-do-and-when-should-you-use-it-cloudsavvy-it\/#Why_Is_Docker_So_Useful\" >Why Is Docker So Useful?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/what-does-docker-do-and-when-should-you-use-it-cloudsavvy-it\/#How_Do_You_Use_Docker\" >How Do You Use Docker?<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#What Does Docker Do, and When Should You Use It? \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage alignnone size-full wp-image-503\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/06\/c454d054.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"700\" height=\"300\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Docker is a tool for running your <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">app<\/a>lications inside containers. Containers package all the dependencies and code your app needs to run into a single file, which will run the same way on any machine.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"What_Is_Docker\"><\/span>What Is Docker?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Docker is similar in concept to Virtual Machines, except it\u2019s much more lightweight. Instead of running an entire separate operating system (which is a massive overhead), Docker runs containers, which use the same host operating system, and only virtualize at a software level.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-492\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/06\/bc4f8762.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"700\" height=\"300\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Docker Engine runs on Linux, Windows, and macOS, and supports Linux and Windows for Docker containers. The exact flavor of Linux doesn\u2019t actually matter; most versions of Linux will run the same kernel, and only differ in the user software. Docker can install this user software to the container, allowing you to run a CentOS container on Ubuntu. You couldn\u2019t though, for example, run FreeBSD on Ubuntu, since the kernels are different.<\/p>\n<p>The Docker container image includes only what your app needs to run. If your app makes use of nginx and Node.js, the container image will include them, but you won\u2019t be burdened with all the other userland apps you\u2019d <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/general\/\" data-internallinksmanager029f6b8e52c=\"3\" title=\"General\" target=\"_blank\" rel=\"noopener\">general<\/a>ly find on Linux.<\/p>\n<p><strong>RELATED:<\/strong> <strong><em>How to Install Docker and Docker Compose on Linux<\/em><\/strong><\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Why_Is_Docker_So_Useful\"><\/span>Why Is Docker So Useful?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Docker takes the same kind of version control and packaging that tools like Git and NPM provide and allows you to use it for your server software. Since your container is a single image, it makes it very easy to version track different builds of your container. And since everything is contained, it makes managing all of your dependencies much easier.<\/p>\n<p>With Docker, your development environment will be exactly the same as your production environment, and exactly the same as everyone else\u2019s development environment, alleviating the problem of \u201cit\u2019s broken on my machine!\u201d<\/p>\n<p>If you wanted to add another server to your cluster, you wouldn\u2019t have to worry about reconfiguring that server and reinstalling all the dependencies you need. Once you build a container, you can share the container file with anyone, and they could easily have your app up and running with a few commands. Docker makes running multiple servers very easy, especially with orchestration engines like <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/kubernetes.io\/\">Kubernetes<\/a>\u00a0and <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.docker.com\/engine\/swarm\/\">Docker Swarm<\/a>.<\/p>\n<p>Docker also allows you to organize your code for deploying on new services. Let\u2019s say you have a web server that you\u2019re using for your application. You likely have a lot of stuff installed on that server, you\u2019ve got an nginx web server\u00a0 for hosting static content, you\u2019ve probably got a database for storing some stuff on the backend, maybe you have an API server running on Express.js as well. Ideally you\u2019d split these up into separate applications to run on separate servers, but development can get messy.<\/p>\n<p>Docker helps clean this up; you can package up your web server and run it with an nginx container, you can package up your API server and run it with a Node.js container, and you can package up your database and run it in it\u2019s own container (though that\u2019s <em>maybe<\/em> <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/blog.newrelic.com\/product-news\/containerizing-databases\/\">not the best idea<\/a>, but it is possible). You can take these three Docker containers and run them all on the same machine. If you need to switch servers, it\u2019s as easy as migrating those containers to a new server. If you need to scale, you can move one of those containers to a new server, or deploy it across a cluster of servers.<\/p>\n<p>Docker can also save you money if you\u2019d like to run multiple apps on a single VPS. If each app has different dependencies, it\u2019s very easy for your server to become cluttered, like a Thanksgiving dinner plate with everything mixing together. With Docker, you can run multiple separate containers with, for example, seperate versions of PHP, like a high school lunch tray with everything separated.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"How_Do_You_Use_Docker\"><\/span>How Do You Use Docker?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In production, there are plenty of services to host Docker containers, including\u00a0<a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/aws.amazon.com\/ecs\/?tag=reviewgeek-20\">AWS ECS<\/a>, <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/click.linksynergy.com\/deeplink?id=2QzUaswX1as&amp;mid=24542&amp;u1=csit\/490&amp;murl=https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fservices%2Fcontainer-instances%2F\">Azure Container Instances<\/a>, <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/marketplace.digitalocean.com\/apps\/docker\">DigitalOcean Docker Droplets<\/a>, and many others. If your provider doesn\u2019t offer managed Docker hosting, you can always install it yourself on your VPS.<\/p>\n<p>In development, Docker containers are simple to run, and only require a few commands.\u00a0To get started you\u2019ll need to install the Docker engine on your host OS. For Windows and macOS, you can use <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.docker.com\/products\/docker-desktop\">Docker Desktop<\/a>, but for Linux you\u2019ll need to install Docker community edition from your package manager. For Debian based distros like Ubuntu, that would be:<\/p>\n<pre>sudo apt-get install docker<\/pre>\n<p>With either install method, you should have access to Docker from the command line now. To verify it\u2019s working, you can run:<\/p>\n<pre>docker run hello-world<\/pre>\n<p>Docker should pull this tutorial image from the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/hub.docker.com\/\">Docker Hub<\/a>, an online repository of many useful container images. You can use many of these images as a base to install your apps into.<\/p>\n<p>Let\u2019s create a simple web server based on nginx. Nginx provides a build on the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/hub.docker.com\/_\/nginx\/\">Docker Hub<\/a> that we can use as a starting point. Create a new directory to store the files, and open it:<\/p>\n<pre>mkdir ~\/dockertest &amp;&amp; cd ~\/dockertest<\/pre>\n<p>Any changes done to the base nginx image will we done with a Dockerfile. Dockerfiles are like makefiles for containers, they define what commands to run when Docker builds the new image with your changes. The Dockerfile is simply called <code>Dockerfile<\/code>, with no extension. Create this file with <code>touch Dockerfile<\/code>, and open it up in a text editor. Paste this in:<\/p>\n<pre>FROM nginx&#13;\nCOPY html \/usr\/share\/nginx\/html<\/pre>\n<p>The first line is a Docker command that tells Docker to base this image on the nginx image from the Hub. The second line is another command that copies over a directory from this local folder (<code>~\/dockertest\/html<\/code>) into the Docker image, in this case replacing the HTML folder for nginx.<\/p>\n<p>You can run plenty of commands in Dockerfiles. For example, if your app needs to install dependencies, you could do something like\u00a0<code>RUN cd src\/ &amp;&amp; npm install<\/code>. Anything that your app needs to bootstrap it\u2019s installation and get up and running is defined in the Dockerfile.<\/p>\n<p>We haven\u2019t actually made the <code>.\/html<\/code>\u00a0directory yet, so go ahead and run:<\/p>\n<pre>mkdir html &amp;&amp; touch html\/index.html<\/pre>\n<p>To create the directory and the entry HTML. Open <code>index.html<\/code> and paste in some dummy HTML:<\/p>\n<pre>&lt;!DOCTYPE html&gt;&#13;\n&lt;html&gt;&#13;\n&lt;body&gt;&#13;\nHello From nginx, inside Docker! Inside, your computer?&#13;\n&lt;\/body&gt;&#13;\n&lt;\/html&gt;<\/pre>\n<p>Now we\u2019re ready to cook our image. Make sure you\u2019re at the root of the project (in <code>~\/dockertest<\/code>, not in the <code>html<\/code>\u00a0folder) and run:<\/p>\n<pre>docker build -t dockertest .<\/pre>\n<p>The period at the end signifies that we\u2019ll be using the current directory as the starting point. Docker should find the Dockerfile, and get to work. It should only take a few seconds though, and when it\u2019s done, you can run it with:<\/p>\n<pre>docker run --name DockerTest -p 8080:80 -d dockertest<\/pre>\n<p>This will start up a new container called DockerTest, using the \u201cdockertest\u201d image we created. The <code>-p<\/code>\u00a0flag binds a local port to a port inside the container, in this case binding nginx\u2019s default HTTP port (port 80) to port 8080 on your local machine. Open up <code>localhost:8080<\/code>\u00a0in your web browser, and you should see nginx running.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-497\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/06\/ce58b2de.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"700\" height=\"150\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>If you wanted further configuration, you could edit nginx\u2019s config files by including\u00a0<code>COPY nginx.conf \/etc\/nginx\/nginx.conf<\/code>\u00a0and writing your own config file. This harder to configure than editing the config file directly, since you will have to rebuild the image on each edit. But for the added benefit of being able to take the same container you use in development and deploy it in production, it\u2019s a pretty fair tradeoff.<\/p>\n<p>If you\u2019d like a more in depth tutorial on networking, deployment, and containerizing existing applications, we recommend <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docker-curriculum.com\/\">reading this guide<\/a>.\n<\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/490\/what-does-docker-do-and-when-should-you-use-it\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#What Does Docker Do, and When Should You Use It? \u2013 CloudSavvy IT&#8221; Docker is a tool for running your applications inside containers. Containers package all the dependencies and code your app needs to run into a single file, which will run the same way on any machine. What Is Docker? Docker is similar in&#8230;<\/p>\n","protected":false},"author":1,"featured_media":262566,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/06\/c454d054.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-262565","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/262565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=262565"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/262565\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/262566"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=262565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=262565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=262565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}