{"id":3627,"date":"2018-02-26T13:27:19","date_gmt":"2018-02-26T13:27:19","guid":{"rendered":"https:\/\/cloudkul.com\/blog\/?p=3627"},"modified":"2018-02-28T08:35:58","modified_gmt":"2018-02-28T08:35:58","slug":"varnish-docker-image-magento-2","status":"publish","type":"post","link":"https:\/\/cloudkul.com\/blog\/varnish-docker-image-magento-2\/","title":{"rendered":"Varnish Docker Image for Magento 2"},"content":{"rendered":"<p>In this blog. we will be looking into documentation for Varnish <a href=\"https:\/\/hub.docker.com\/r\/webkul\/varnish_for_magento2\/\">docker image<\/a>, and its applicability with Magento 2.<em>\u00a0<\/em><\/p>\n<p><em>This Docker Image can be used to run a Docker container with Varnish Cache as one of its service. Varnish Configuration File present at location \/etc\/varnish\/default.vcl is fully compatible with Magento 2 latest version on OS ubuntu 16.04.<\/em><\/p>\n<p>To begin with this image, docker must be installed and running on your server. To pull this Image, run the following command on your docker installed server:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\">docker pull webkul\/varnish_for_magento2<\/pre>\n<p>&nbsp;<\/p>\n<p>Now when Image has been pulled, you can check its presence by running command:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\">docker images<\/pre>\n<p>&nbsp;<\/p>\n<p>Now, you can run docker container from this Image to start a Varnish Cache server. There must be a Magento 2 running on the (same or different) server. Varnish will act as a HTTP accelerator for your Magento 2 server.<\/p>\n<p>Inside the docker container, <strong>Varnish cache will run on port 6081<\/strong>. You can map it whichever port on the host. So let&#8217;s launch the container from the image as:<\/p>\n<p><strong>docker run -tidp host_port:container_port -e BACKEND_PORT=magento2_server_port -e BACKEND_HOST=magento2_server_IP webkul\/varnish_for_magento2<\/strong><\/p>\n<p>Let us assume our Magento 2 server is running on port 80, server IP is 192.168.X.X. Also, the Varnish server is on same server. This port and IP address will act as Varnish <strong>backend port<\/strong>\u00a0and <strong>backend host<\/strong> respectively. As Varnish is on same server, we will have to assign a port other than 80.<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\">docker run -tidp 8080:6081 -e BACKEND_PORT=80 -e BACKEND_HOST=192.168.X.X webkul\/varnish_for_magento2<\/pre>\n<p>&nbsp;<\/p>\n<p>You can check the running container by command:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\">docker ps<\/pre>\n<p>&nbsp;<\/p>\n<p>Hit 192.168.X.X:8080 on browser to check if it is working or not.<\/p>\n<p>Also, for Varnish Cache server to run on port 80 presuming that your webserver is running on some other port:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\">docker run -tidp 80:6081 -e BACKEND_PORT=8080 -e BACKEND_HOST=192.168.X.X webkul\/varnish_for_magento2<\/pre>\n<p>&nbsp;<\/p>\n<p>Your server will be running on 192.168.X.X .<\/p>\n<p>If Varnish and Magento 2 server is running on different servers, we can run both servers on port 80. Let us say Magento 2 server is on 192.168.X.X and Varnish Cache server is on 192.168.X.Y. Run this command:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\">docker run -tidp 80:6081 -e BACKEND_PORT=80 -e BACKEND_HOST=192.168.X.X webkul\/varnish_for_magento2<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Please take a note that if Varnish and Webserver are on separate server then your domain should be mapped with IP address of Varnish Server.<\/strong><\/p>\n<p>Hit 192.168.X.Y on browser to check.<\/p>\n<p>We have setup our Varnish Cache server and now we have to configure Magento 2 to use Varnish Cache instead of default built-in cache. <em><strong>Log In to Magento 2 Admin and and go to Stores -&gt; Configuration -&gt; Advanced -&gt; System -&gt; Full Page Cache. Modify Caching application and set Varnish configuration. <\/strong><\/em>Then refresh all the Cache.<\/p>\n<p>Finally, to check if Varnish server is caching or not, <strong>set your Magento 2 in developer mode<\/strong>. Curl the URL with Varnish port. As if Varnish cache is running on port 80 and our IP is 192.168.X.X, then:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\">curl -I\u00a0192.168.X.X<\/pre>\n<p>&nbsp;<\/p>\n<p>or in case of port 8080:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\">curl -I 192.168.X.X:6081<\/pre>\n<p>&nbsp;<\/p>\n<p>If you see headers like <strong>X-Magento-Cache-Debug, X-Varnish-Cache getting values as HIT and header Age is increasing with each Curl request<\/strong>, then you Varnish Cache is working properly.<\/p>\n<p>Visit\u00a0<a href=\"https:\/\/hub.docker.com\/r\/webkul\/varnish_for_magento2\/\">https:\/\/hub.docker.com\/r\/webkul\/varnish_for_magento2\/<\/a> for Docker Image Repository.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog. we will be looking into documentation for Varnish docker image, and its <a class=\"text-primary\" title=\"read more\" href=\"https:\/\/cloudkul.com\/blog\/varnish-docker-image-magento-2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":7,"featured_media":3637,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Varnish Docker Image for Magento 2 - Cloudkul<\/title>\n<meta name=\"description\" content=\"This Docker Image can be used to run a Docker container with Varnish Cache as one of its service.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudkul.com\/blog\/varnish-docker-image-magento-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Varnish Docker Image for Magento 2 - Cloudkul\" \/>\n<meta property=\"og:description\" content=\"This Docker Image can be used to run a Docker container with Varnish Cache as one of its service.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudkul.com\/blog\/varnish-docker-image-magento-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudkul\" \/>\n<meta property=\"article:published_time\" content=\"2018-02-26T13:27:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-02-28T08:35:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2018\/02\/download.png\" \/>\n\t<meta property=\"og:image:width\" content=\"848\" \/>\n\t<meta property=\"og:image:height\" content=\"422\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Alankrit Srivastava\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudkul.com\/blog\/varnish-docker-image-magento-2\/\",\"url\":\"https:\/\/cloudkul.com\/blog\/varnish-docker-image-magento-2\/\",\"name\":\"Varnish Docker Image for Magento 2 - Cloudkul\",\"isPartOf\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\"},\"datePublished\":\"2018-02-26T13:27:19+00:00\",\"dateModified\":\"2018-02-28T08:35:58+00:00\",\"author\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/fc06bfd7f18d9a606dd94062d205af16\"},\"description\":\"This Docker Image can be used to run a Docker container with Varnish Cache as one of its service.\",\"breadcrumb\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/varnish-docker-image-magento-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudkul.com\/blog\/varnish-docker-image-magento-2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudkul.com\/blog\/varnish-docker-image-magento-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Varnish Docker Image for Magento 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\",\"url\":\"https:\/\/cloudkul.com\/blog\/\",\"name\":\"Cloudkul\",\"description\":\"Host your eCommerce Store on AWS with Optimized Performance\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cloudkul.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/fc06bfd7f18d9a606dd94062d205af16\",\"name\":\"Alankrit Srivastava\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/955c3dda2678272c436c5153832e401f?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/955c3dda2678272c436c5153832e401f?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"caption\":\"Alankrit Srivastava\"},\"description\":\"DevOps Manager at Webkul Software Privated Limited\",\"sameAs\":[\"http:\/\/cloudkul.com\"],\"url\":\"https:\/\/cloudkul.com\/blog\/author\/alankrit-srivastava256\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Varnish Docker Image for Magento 2 - Cloudkul","description":"This Docker Image can be used to run a Docker container with Varnish Cache as one of its service.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cloudkul.com\/blog\/varnish-docker-image-magento-2\/","og_locale":"en_US","og_type":"article","og_title":"Varnish Docker Image for Magento 2 - Cloudkul","og_description":"This Docker Image can be used to run a Docker container with Varnish Cache as one of its service.","og_url":"https:\/\/cloudkul.com\/blog\/varnish-docker-image-magento-2\/","og_site_name":"Cloudkul","article_published_time":"2018-02-26T13:27:19+00:00","article_modified_time":"2018-02-28T08:35:58+00:00","og_image":[{"width":848,"height":422,"url":"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2018\/02\/download.png","type":"image\/png"}],"author":"Alankrit Srivastava","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/cloudkul.com\/blog\/varnish-docker-image-magento-2\/","url":"https:\/\/cloudkul.com\/blog\/varnish-docker-image-magento-2\/","name":"Varnish Docker Image for Magento 2 - Cloudkul","isPartOf":{"@id":"https:\/\/cloudkul.com\/blog\/#website"},"datePublished":"2018-02-26T13:27:19+00:00","dateModified":"2018-02-28T08:35:58+00:00","author":{"@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/fc06bfd7f18d9a606dd94062d205af16"},"description":"This Docker Image can be used to run a Docker container with Varnish Cache as one of its service.","breadcrumb":{"@id":"https:\/\/cloudkul.com\/blog\/varnish-docker-image-magento-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudkul.com\/blog\/varnish-docker-image-magento-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cloudkul.com\/blog\/varnish-docker-image-magento-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Varnish Docker Image for Magento 2"}]},{"@type":"WebSite","@id":"https:\/\/cloudkul.com\/blog\/#website","url":"https:\/\/cloudkul.com\/blog\/","name":"Cloudkul","description":"Host your eCommerce Store on AWS with Optimized Performance","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudkul.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/fc06bfd7f18d9a606dd94062d205af16","name":"Alankrit Srivastava","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/955c3dda2678272c436c5153832e401f?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/955c3dda2678272c436c5153832e401f?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","caption":"Alankrit Srivastava"},"description":"DevOps Manager at Webkul Software Privated Limited","sameAs":["http:\/\/cloudkul.com"],"url":"https:\/\/cloudkul.com\/blog\/author\/alankrit-srivastava256\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/3627"}],"collection":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/comments?post=3627"}],"version-history":[{"count":13,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/3627\/revisions"}],"predecessor-version":[{"id":3629,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/3627\/revisions\/3629"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/media\/3637"}],"wp:attachment":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/media?parent=3627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/categories?post=3627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/tags?post=3627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}