{"id":349891,"date":"2021-10-07T20:00:00","date_gmt":"2021-10-07T17:00:00","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/should-you-run-a-database-in-docker-cloudsavvy-it\/"},"modified":"2021-10-07T20:00:00","modified_gmt":"2021-10-07T17:00:00","slug":"should-you-run-a-database-in-docker-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/should-you-run-a-database-in-docker-cloudsavvy-it\/","title":{"rendered":"#Should You Run a Database in Docker? \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-6a29916977c87\" 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-6a29916977c87\" 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\/should-you-run-a-database-in-docker-cloudsavvy-it\/#Docker_Can_Handle_Stateful_Workloads\" >Docker Can Handle Stateful Workloads<\/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\/should-you-run-a-database-in-docker-cloudsavvy-it\/#Should_You_Choose_Docker_for_Your_Database\" >Should You Choose Docker for Your Database?<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#Should You Run a Database in Docker? \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage imgchk9 alignnone wp-image-503 size-full\" srcset=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/06\/c454d054.png?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 400w, https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/06\/c454d054.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 1200w\" sizes=\"auto, 400w, 1200w\" 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=\"Docker logo\" width=\"700\" height=\"300\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Containerizing server workloads is growing ever more popular, and it\u2019s becoming increasingly common to see web server deployments running in containers. Can the same benefits be <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>lied to databases?<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Docker_Can_Handle_Stateful_Workloads\"><\/span>Docker Can Handle Stateful Workloads<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>It\u2019s best to start this off by asking a different question: <em>C<\/em><em>an<\/em> you even run a database in Docker? In <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/general\/\" data-internallinksmanager029f6b8e52c=\"3\" title=\"General\" target=\"_blank\" rel=\"noopener\">general<\/a>, Docker isn\u2019t designed for stateful services. One of the major selling points of containers is that they can be stopped and started at will, usually connecting to an authoritative data source, like a database, to store their state. All the data in the container is ephemeral, and is destroyed when the container is deleted.<\/p>\n<p>This makes running stateful workloads particularly challenging, but luckily Docker does have some tools for dealing with state: volume and bind mounts. These allow you to mount a location on the host machine to a location in the container, which will store data even when the container shuts down. This way, you can run containers long-term without worrying about the data being lost.<\/p>\n<p>Volume mounts are the preferred way of handling most scenarios. They allow you to create a volume, which is managed by Docker:<\/p>\n<pre>docker volume create my-volume<\/pre>\n<p>Then mount that volume to a target location inside the container:<\/p>\n<pre>docker run --mount source=my-volume,target=\/app<\/pre>\n<p>Bind mounts are simpler. They\u2019re what volumes use under the hood, but they allow you to manually set the location on the host disk rather than having it managed through Docker.<\/p>\n<pre>docker run ~\/nginxlogs:\/var\/log\/nginx<\/pre>\n<p>In practice, using these mounts can be a bit more complicated. Many managed Docker services, like AWS\u2019s ECS, or managed Kubernetes, don\u2019t give you direct access to the underlying server, and as such you won\u2019t be able to directly make bind mount connections. Usually this is solved with a service like EFS, which <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/aws.amazon.com\/blogs\/compute\/using-amazon-efs-to-persist-data-from-amazon-ecs-containers\/?tag=reviewgeek-20\">allows mounting to ECS containers<\/a>, or with an external datastore, like a database.<\/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=\"Should_You_Choose_Docker_for_Your_Database\"><\/span>Should You Choose Docker for Your Database?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Docker is generally not great for handling state. Docker-based workloads usually outsource this problem to databases. With a database being the solution to the problem, is it practical to put your database in Docker?<\/p>\n<p>Largely, the answer is \u201cnot usually.\u201d Docker has come a long way since its inception, and it isn\u2019t a terrible or \u201cwrong\u201d idea to containerize databases anymore. It certainly can be done, and has some benefits to it. However, for most general workloads, the benefits don\u2019t outweigh the complications.<\/p>\n<p>To see why, let\u2019s look at the benefits Docker brings to the table:<\/p>\n<ul>\n<li>Easy scaling: servers can be created and destroyed quickly to meet demand<\/li>\n<li>Easier CI\/CD tooling: automated builds are trivial<\/li>\n<li>Codification of your infrastructure: all underlying libraries and setup are handled in the Dockerfile<\/li>\n<\/ul>\n<p>Most of these don\u2019t exactly transfer well to database workloads, which are often long-term endeavors that favor data integrity above all else. You don\u2019t generally want to be autoscaling most databases; they don\u2019t usually themselves receive regular code updates, and as such don\u2019t benefit as much from running in containers. And, if you\u2019re just mounting a local storage drive anyway, why not run it outside Docker?<\/p>\n<p>If you\u2019re looking to free yourself from the complexities of managing databases, Docker isn\u2019t the tool for the job. It\u2019s simply unnecessary complication for a workload that can easily run on a standard VPS. You\u2019ll likely be much better off using a fully managed database-as-a-service, like <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/aws.amazon.com\/rds\/?tag=reviewgeek-20\">AWS\u2019s RDS<\/a>. This brings a lot of the automation that Docker is good for, without any of the headache of doing it yourself.<\/p>\n<p>The main place where Docker can be useful for database workloads is in development environments. Docker makes it easy to spin up new databases with different configuration, which makes for quick testing. In production, however, the rules are generally stricter.\n<\/p><\/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\/5414\/should-you-run-a-database-in-docker\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#Should You Run a Database in Docker? \u2013 CloudSavvy IT&#8221; Containerizing server workloads is growing ever more popular, and it\u2019s becoming increasingly common to see web server deployments running in containers. Can the same benefits be applied to databases? Docker Can Handle Stateful Workloads It\u2019s best to start this off by asking a different question:&#8230;<\/p>\n","protected":false},"author":1,"featured_media":349892,"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-349891","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\/349891","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=349891"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/349891\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/349892"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=349891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=349891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=349891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}