{"id":384195,"date":"2021-12-21T17:59:44","date_gmt":"2021-12-21T14:59:44","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-quickly-deploy-redis-as-a-docker-container-cloudsavvy-it\/"},"modified":"2021-12-21T17:59:44","modified_gmt":"2021-12-21T14:59:44","slug":"how-to-quickly-deploy-redis-as-a-docker-container-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-quickly-deploy-redis-as-a-docker-container-cloudsavvy-it\/","title":{"rendered":"#How to Quickly Deploy Redis as a Docker Container \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-6a28149e54b61\" 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-6a28149e54b61\" 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\/how-to-quickly-deploy-redis-as-a-docker-container-cloudsavvy-it\/#Getting_Started\" >Getting Started<\/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\/how-to-quickly-deploy-redis-as-a-docker-container-cloudsavvy-it\/#Data_Storage\" >Data Storage<\/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\/how-to-quickly-deploy-redis-as-a-docker-container-cloudsavvy-it\/#Configuring_Your_Server\" >Configuring Your Server<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-quickly-deploy-redis-as-a-docker-container-cloudsavvy-it\/#Managing_Redis_Security\" >Managing Redis Security<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-quickly-deploy-redis-as-a-docker-container-cloudsavvy-it\/#Using_Your_Redis_Installation\" >Using Your Redis Installation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-quickly-deploy-redis-as-a-docker-container-cloudsavvy-it\/#Summary\" >Summary<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How to Quickly Deploy Redis as a Docker Container \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage aligncenter size-full wp-image-14994\" data-pagespeed-lazy-srcset=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/12\/c554ab32.jpeg?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 400w, https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/12\/c554ab32.jpeg?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 1200w\" sizes=\"auto, 400w, 1200w\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/12\/c554ab32.jpeg?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Redis logo on a red background\" width=\"1202\" height=\"677\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/redis.io\">Redis<\/a> is an in-memory key-value store which can save abstract data structures with high performance. The open-source software is typically used for database, messaging, and caching functions.<\/p>\n<p>Docker is the leading toolkit for packaging <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 into containers. It lets you isolate software components into independent environments with their own filesystem.<\/p>\n<p>In this guide, we\u2019ll use Docker to quickly deploy Redis using the official image <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/hub.docker.com\/_\/redis\">on Docker Hub<\/a>. Compared to bare metal installation, Docker enables a simpler set up procedure and won\u2019t pollute your host with new packages. Make sure you\u2019ve got a functioning Docker installation on your host before you continue.<\/p>\n<h2 id=\"getting-started\"><span class=\"ez-toc-section\" id=\"Getting_Started\"><\/span>Getting Started<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The Redis image includes both the server component and the official CLI. It\u2019s preconfigured to launch the server with functioning default config values when you start a new container.<\/p>\n<p>Variations of the image are available to cover different Redis versions (5.0 and 6.0) and operating systems (Alpine and Debian). Browse the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/hub.docker.com\/_\/redis?tab=tags\">tag list<\/a> to find the best option for your environment.<\/p>\n<p>The simplest deployment is as follows:<\/p>\n<pre><code>docker run --name redis -d -p 6379:6379 redis:6.0<\/code><\/pre>\n<p>This starts a new container called <code>redis<\/code> running Redis 6.0. The <code>-d<\/code> flag is used to detach from the container. The server will stay up in the background until you stop the container with <code>docker stop redis<\/code>.<\/p>\n<p>Redis listens on port 6379 by default. The <code>-p<\/code> flag binds this port to your host. Your applications will be able to access Redis on <code>localhost:6379<\/code>. Beware that this is insecure though \u2013 if your machine is internet-exposed, anyone could access your Redis data!<\/p>\n<h2 id=\"data-storage\"><span class=\"ez-toc-section\" id=\"Data_Storage\"><\/span>Data Storage<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Redis supports several <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/redis.io\/topics\/persistence\">persistence mechanisms<\/a> that can save your in-memory database to disk. The data will be saved to the <code>\/data<\/code> directory in the container. As Docker containers are ephemeral, you need to mount a volume to this directory. Otherwise your data will be lost when your container stops.<\/p>\n<pre><code>docker run --name redis -d &#13;\n    -v redis-data:\/data&#13;\n    redis:6.0 --save 60 1<\/code><\/pre>\n<p>The <code>--save<\/code> flag is passed to the Redis server. It configures the persistence strategy to use. This example writes a snapshot of your database every <code>60<\/code> seconds. The operation\u2019s skipped unless <code>1<\/code> database write has occurred since the last snapshot.<\/p>\n<p>A Docker volume called <code>redis-data<\/code> is created by the <code>-v<\/code> flag. This will store your data outside the container so it\u2019ll remain accessible after restarts. The volume will persist until it\u2019s deleted by running <code>docker volumes rm redis-data<\/code>.<\/p>\n<h2 id=\"configuring-your-server\"><span class=\"ez-toc-section\" id=\"Configuring_Your_Server\"><\/span>Configuring Your Server<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The quickest way to add config parameters is to pass CLI arguments to the Redis server as part of your <code>docker run<\/code> command. This is illustrated by the <code>--save<\/code> example above. Anything after the image name in <code>docker run<\/code> will get passed through to the command executed inside the container. In the case of the Redis image, that command is the Redis server.<\/p>\n<p>Using CLI flags quickly becomes repetitive. You can make Redis <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/raw.githubusercontent.com\/redis\/redis\/6.2\/redis.conf\">use a config file<\/a> by passing a path as the server\u2019s first argument. This file is conventionally located at <code>\/usr\/local\/etc\/redis\/redis.conf<\/code>. Use a Docker bind mount to get a <code>redis.conf<\/code> from your local filesystem mounted into the container:<\/p>\n<pre><code>docker run --name redis -d &#13;\n    -v redis-data:\/data&#13;\n    -v .\/redis-conf:\/usr\/local\/etc\/redis&#13;\n    redis:6.0 \/usr\/local\/etc\/redis.conf<\/code><\/pre>\n<p>Place a <code>redis.conf<\/code> inside <code>redis-conf<\/code> in your working directory. Docker will mount this path into the container, giving Redis access to the file specified in the <code>docker run<\/code> command.<\/p>\n<h2 id=\"managing-redis-security\"><span class=\"ez-toc-section\" id=\"Managing_Redis_Security\"><\/span>Managing Redis Security<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The Redis Docker images are configured to run Redis in unprotected mode by default. This makes it easier to access the Redis server from your other Docker containers, using Docker networks. However, it also means anything that can reach your container will have full access to your data.<\/p>\n<p><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/redis.io\/topics\/security\">Protected mode is<\/a> a Redis feature that only responds to unauthenticated queries issued from your host\u2019s loopback addresses such as <code>localhost<\/code>. You can enable it by adding <code>protected-mode yes<\/code> to your <code>redis.conf<\/code>. When used with a Dockerized installation, this will result in Redis only being accessible within its own container, which is not usually ideal.<\/p>\n<p>You can set up basic password authentication instead by adding <code>requirepass example<\/code> to your <code>redis.conf<\/code>. Redis will only accept queries from clients that present the configured password. Redis 6 also supports more fully-featured <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/redis.io\/topics\/acl\">access control<\/a> that lets you set up multiple user accounts with differing privileges.<\/p>\n<p>To use authentication, follow the guidance in the preceding section to create a Redis config file and mount it into your container. If you don\u2019t want to set up a password, keep your installation secure by only joining it to the Docker networks needed for your application. Do not bind port 6379 to your host without setting up authentication first.<\/p>\n<h2 id=\"using-your-redis-installation\"><span class=\"ez-toc-section\" id=\"Using_Your_Redis_Installation\"><\/span>Using Your Redis Installation<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Now that Redis is fully set up, you can move on to accessing it from your clients. If you\u2019re connecting from your host, you can use the Docker container\u2019s IP (visible by running <code>docker inspect redis<\/code>, adjusted for your container\u2019s name) and port <code>6379<\/code>.<\/p>\n<p>To access Redis from another Docker container, it\u2019s best to join both the containers into a Docker network:<\/p>\n<pre><code>docker network create redis&#13;\ndocker run --name redis --network redis -d redis:6.0&#13;\ndocker run --name api --network redis -d my-api:latest<\/code><\/pre>\n<p>Now your application container will be able to reach Redis via port 6379 on the <code>redis<\/code> hostname. Docker makes container names accessible as hostnames when they share a Docker network.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-14996\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/12\/3dadd844.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"729\" height=\"223\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You can manually interact with your database using the <code>redis-cli<\/code> binary that\u2019s included in the container image. Start your container in detached mode (<code>-d<\/code>) so it runs in the background. Then use <code>docker exec<\/code> to run the <code>redis-cli<\/code> command:<\/p>\n<pre><code>docker exec -it redis-container redis-cli<\/code><\/pre>\n<p>This will drop you into a Redis CLI session within your container.<\/p>\n<h2 id=\"conclusion\"><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Docker makes it quick and easy to start a new Redis instance without installing the software onto your machine. Use the official Docker image to start your container, then add command flags or mount a config file to suit your needs.<\/p>\n<p>Two things to always keep in mind are storage and security: if you need to use Redis persistence features, you should use a Docker volume to avoid losing your data. Remember that Dockerized Redis defaults to unprotected mode with no authentication, so exposing port 6379 could have disastrous consequences in a worst case scenario.\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\/14993\/how-to-quickly-deploy-redis-as-a-docker-container\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How to Quickly Deploy Redis as a Docker Container \u2013 CloudSavvy IT&#8221; Redis is an in-memory key-value store which can save abstract data structures with high performance. The open-source software is typically used for database, messaging, and caching functions. Docker is the leading toolkit for packaging applications into containers. It lets you isolate software components&#8230;<\/p>\n","protected":false},"author":1,"featured_media":384196,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/12\/c554ab32.jpeg","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-384195","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\/384195","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=384195"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/384195\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/384196"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=384195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=384195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=384195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}