{"id":3359,"date":"2017-09-07T12:48:12","date_gmt":"2017-09-07T12:48:12","guid":{"rendered":"https:\/\/cloudkul.com\/blog\/?p=3359"},"modified":"2018-07-17T09:22:03","modified_gmt":"2018-07-17T09:22:03","slug":"magento-2-and-varnish-cache-integration-with-docker-compose","status":"publish","type":"post","link":"https:\/\/cloudkul.com\/blog\/magento-2-and-varnish-cache-integration-with-docker-compose\/","title":{"rendered":"Magento 2 and Varnish Cache Integration With Docker-Compose"},"content":{"rendered":"<p>In our last\u00a0<a href=\"https:\/\/cloudkul.com\/blog\/magento-2-docker-compose\/\">blog,<\/a>\u00a0after being introduced to docker-compose, we had discussed the deployment of multi-container architecture in Docker. Using this tool we had setup Magento 2 running with apache2 server and mysql-server on separate containers interlinked with each other. We had also discussed the volume\u00a0mapping, ports allocation, containers linking etc techniques for docker-compose.yml file.<\/p>\n<p>As we are now familiar with docker and docker-compose, their working and their integration with applications (Magento 2 in our case), we will now take a further step ahead. In our previous blogs, we have installed Magento 2 with default configurations. We were focused on infrastructure performance rather than application optmisation. Moving further, in this blog we will discuss integration of Varnish cache with Magento 2 on the architecture of Docker and of course we will be using docker-compose to setup this architecture as we did earlier.<\/p>\n<p>&nbsp;<\/p>\n<h2><strong>Introduction To Varnish Cache<\/strong><\/h2>\n<p>&nbsp;<\/p>\n<p>If you are familiar with Magento 2 and own your store then you might have heard of Varnish cache once in a while. If not all of you, then those who are struggling with high traffic on their Magento 2 store, they must have considered using some cache server at some point. Those who are not familiar with Varnish cache, following lines are for you,<\/p>\n<p>&nbsp;<\/p>\n<blockquote><p><em><strong>Quoting from Varnish docs,\u00a0Varnish cache is a web application accelerator also known as a caching HTTP reverse proxy. It\u00a0is a powerful open source HTTP engine\/reverse HTTP proxy that can speed up a website by up to 1000 percent by doing exactly what its name implies: caching (or storing) a copy of a webpage the first time a user visits.\u00a0Varnish cache\u00a0visits your server once to cache the page, then all future requests for the same page will be served by\u00a0Varnish cache.\u00a0<\/strong><\/em><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>Unlike other web-accelerators, Varnish cache deals only with HTTP traffic. The key element in Varnish cache setup is its Varnish Configuration Language (VCL) file. VCL files are needed to be customised for specific frameworks or applications. Default VCL file does not work directly with all the applications. If you consider Varnish Cache as a radio, then you have it tune it according your server needs. Luckily for us, Magento 2 works out of box with Varnish Cache and provides its own VCL file for its setup. Also from Magento 2 docs,<\/p>\n<p>&nbsp;<\/p>\n<blockquote><p><em><strong>\u201cWe strongly recommend you use Varnish in production. The built-in full-page caching (to either the file system or database) is much slower than Varnish, and Varnish is designed to accelerate HTTP traffic.\u201d<\/strong><\/em><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h2><strong>Magento 2 And Varnish Cache Setup With Docker-Compose<\/strong><\/h2>\n<p>&nbsp;<\/p>\n<p>As we are still on our multi-container docker architecture, <strong>we will be using separate containers for apache2 server, mysql-server and varnish cache server for its integration with Magento 2 on Ubuntu 16.04.<\/strong> As separate containers will require inter-linking with each other, we will be using docker-compose tool to achieve this architecture.<\/p>\n<p>The parent directory holding all the files\/directories will be considered as the project name. Custom project name can also be in set docker-compose.yml file. Here <em><strong>we are creating separate directories for apache2, mysql server and varnish cache server setup that hold their Dockerfile(s) and their associated volumes.<\/strong><\/em><\/p>\n<p>Take a note that: following the same approach,\u00a0<em><strong>Magento 2 files will be placed on our host. As it is a good practice to keep application files on host so that it will not be lost if containers or images get accidentally removed. These magento files will be mapped from host to running docker container<\/strong>.<\/em><\/p>\n<p>We are also using supervisor to control all three of our servers\u00a0in their respective containers. Apart from controlling these servers, supervisor is also running various commands and scripts that will be mentioned later in this blog.<\/p>\n<p>To begin with create a directory on your Ubuntu 16.04 server for this project. Our directory architecture will be something like:<\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li><strong>docker-compose.yml<\/strong><\/li>\n<li><strong>web_server\u00a0<\/strong><\/li>\n<\/ul>\n<blockquote><p><em>Dockerfile<\/em><\/p>\n<p><em>supervisord.conf<\/em><\/p><\/blockquote>\n<ul>\n<li><strong>\u00a0database_server<\/strong><\/li>\n<\/ul>\n<blockquote><p><em>Dockerfile<\/em><\/p>\n<p><em>mysql.sh<\/em><\/p>\n<p><em>supervisord.conf<\/em><\/p><\/blockquote>\n<ul>\n<li><strong>cache_server<\/strong><\/li>\n<\/ul>\n<blockquote><p>Dockerfile<\/p>\n<p>default.vcl<\/p>\n<p>supervisord.conf<\/p>\n<p>varnish<\/p><\/blockquote>\n<ul>\n<li><strong>magento2<\/strong><\/li>\n<\/ul>\n<blockquote><p><em>Unarchived Magento 2 files and directories.<\/em><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>The<em>\u00a0docker-compose.yml<\/em>\u00a0file is shown below:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\">version: '3'\r\nservices:\r\n  cache_server:\r\n    build:\r\n      context: .\/cache_server\/\r\n    container_name: varnish\r\n    depends_on:\r\n      - web_server\r\n    volumes:\r\n      - .\/cache_server\/default.vcl:\/etc\/varnish\/default.vcl\r\n      - .\/cache_server\/varnish:\/etc\/default\/varnish\r\n      - .\/cache_server\/supervisord.conf:\/etc\/supervisor\/conf.d\/supervisord.conf\r\n    ports:\r\n      - \"80:80\"\r\n      - \"6082:6082\"\r\n    links:\r\n      - web_server\r\n\r\n  web_server:\r\n    build:\r\n      context: .\/web_server\/\r\n    container_name: apache2\r\n    volumes:\r\n      - .\/magento2:\/var\/www\/html  \r\n      - .\/web_server\/supervisord.conf:\/etc\/supervisor\/conf.d\/supervisord.conf\r\n    ports:\r\n      - \"8080:8080\"\r\n    links:\r\n      - database_server\r\n\r\n  database_server:\r\n    build:\r\n      context: .\/database_server\/\r\n      args:\r\n        - mysql_password=mention_your_mysql_root_password\r\n        - mysql_database=mention_your_database_name\r\n    container_name: mysql\r\n    volumes: \r\n      - .\/database_server\/supervisord.conf:\/etc\/supervisor\/conf.d\/supervisord.conf\r\n      - .\/database_server\/mysql.sh:\/etc\/mysql.sh\r\n    ports:\r\n- \"3306:3306\"<\/pre>\n<p>&nbsp;<\/p>\n<p>Here in YAML file above, we are defining three\u00a0services: cache_server, web_server and database_server.<\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li>The <i>cache_server<\/i> is associated with our <em>Varnish cache server<\/em> configuration. Container name defined is <em>varnish<\/em>, linked to <em>web_server<\/em> and <em>port 80 &amp; 6082<\/em> is allocated to it. There are three files that are being mapped from host to docker container and &#8220;context&#8221; points to its Dockerfile installing <em>Varnish version 4.1.<\/em><\/li>\n<li>The <em>web_server<\/em> is associated with our <em>apache server<\/em> configuration. Container name defined for this service is <em>apache2<\/em>, linked to <em>database_server<\/em> and<em> port 8080<\/em> is allocated to it. There are <em>four volumes or files are being mapped from host to docker container<\/em> and \u201ccontext\u201d under \u201cbuild\u201d points to location of its Dockerfile.<\/li>\n<li>Also, the service <em>database_server<\/em> is associated with <em>mysql-server<\/em>. Container name is defined as <em>mysql<\/em> and <em>port 3306<\/em> is allocated to it. <em><strong>Mysql root password will be passed as build argument<\/strong><\/em> and their are <em>two volumes\/files mapped from host to docker container<\/em>. Same as <em>web_server<\/em>, \u201ccontext\u201d points to location of its Dockerfile installing <em>mysql-server-5.7.<\/em><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>Lets take a look in our\u00a0<em>web_server\u00a0directory<\/em>. It contains 2 files.\u00a0<em>Dockerfile<\/em>\u00a0is shown below:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\">FROM ubuntu:16.04\r\n\r\nLABEL maintainer=\"Alankrit Srivastava &lt;alankrit.srivastava256@webkul.com&gt;\"\r\n\r\nRUN apt-get update \\\r\n    &amp;&amp; apt-get -y install apache2 nano mysql-client \\\r\n    &amp;&amp; a2enmod rewrite \\\r\n    &amp;&amp; a2enmod headers \\\r\n    &amp;&amp; export LANG=en_US.UTF-8 \\\r\n    &amp;&amp; apt-get update \\\r\n    &amp;&amp; apt-get install -y software-properties-common \\\r\n    &amp;&amp; apt-get install -y language-pack-en-base \\\r\n    &amp;&amp; LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej\/php \\\r\n    &amp;&amp; apt-get update \\\r\n    &amp;&amp; apt-get -y install php7.1 php7.1-curl php7.1-intl php7.1-gd php7.1-dom php7.1-mcrypt php7.1-iconv php7.1-xsl php7.1-mbstring php7.1-ctype   php7.1-zip php7.1-pdo php7.1-xml php7.1-bz2 php7.1-calendar php7.1-exif php7.1-fileinfo php7.1-json php7.1-mysqli php7.1-mysql php7.1-posix php7.1-tokenizer php7.1-xmlwriter php7.1-xmlreader php7.1-phar php7.1-soap php7.1-mysql php7.1-fpm php7.1-bcmath libapache2-mod-php7.1 \\\r\n    &amp;&amp; sed -i -e\"s\/^memory_limit\\s*=\\s*128M\/memory_limit = 512M\/\" \/etc\/php\/7.1\/apache2\/php.ini \\\r\n    &amp;&amp; rm \/var\/www\/html\/* \\\r\n    &amp;&amp; sed -i \"s\/None\/all\/g\" \/etc\/apache2\/apache2.conf \\\r\n    &amp;&amp; sed -i \"s\/80\/8080\/g\" \/etc\/apache2\/ports.conf \/etc\/apache2\/sites-enabled\/000-default.conf \\\r\n##install supervisor and setup supervisord.conf file\r\n    &amp;&amp; apt-get install -y supervisor \\\r\n    &amp;&amp; mkdir -p \/var\/log\/supervisor\r\nenv APACHE_RUN_USER    www-data\r\nenv APACHE_RUN_GROUP   www-data\r\nenv APACHE_PID_FILE    \/var\/run\/apache2.pid\r\nenv APACHE_RUN_DIR     \/var\/run\/apache2\r\nenv APACHE_LOCK_DIR    \/var\/lock\/apache2\r\nenv APACHE_LOG_DIR     \/var\/log\/apache2\r\nenv LANG               C\r\n\r\nWORKDIR \/var\/www\/html\r\n\r\nCMD [\"\/usr\/bin\/supervisord\"]\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>And at last we have\u00a0<em>supervisord.conf<\/em>\u00a0file that supervisor use to run apache2 server and ownership commands. Its contents are shown below:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\">[supervisord]\r\nnodaemon=true\r\n\r\n[program:apache2]\r\ncommand=\/bin\/bash -c \"source \/etc\/apache2\/envvars &amp;&amp; exec \/usr\/sbin\/apache2 -DFOREGROUND\"\r\n\r\n[program:user_permission]\r\ncommand=\/bin\/bash -c \"chown -R www-data: \/var\/www\/\"<\/pre>\n<p>&nbsp;<\/p>\n<p>Moving on to our\u00a0<em>database_server directory,\u00a0<\/em>it contains 3 files.\u00a0<em>Dockerfile<\/em>\u00a0is shown below:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\">FROM ubuntu:16.04\r\n\r\nLABEL maintainer=\"Alankrit Srivastava &lt;alankrit.srivastava256@webkul.com&gt;\"\r\n\r\nARG mysql_password\r\nARG mysql_database\r\nenv MYSQL_ROOT_PASSWORD ${mysql_password}\r\nenv MYSQL_DATABASE ${mysql_database}\r\n\r\nRUN apt-get update \\\r\n&amp;&amp; echo \"mysql-server-5.7 mysql-server\/root_password password ${mysql_password}\" | debconf-set-selections \\\r\n&amp;&amp; echo \"mysql-server-5.7 mysql-server\/root_password_again password ${mysql_password}\" | debconf-set-selections \\\r\n&amp;&amp; DEBIAN_FRONTEND=noninteractive apt-get -y install mysql-server-5.7 &amp;&amp; \\\r\n    mkdir -p \/var\/lib\/mysql &amp;&amp; \\\r\n    mkdir -p \/var\/run\/mysqld &amp;&amp; \\\r\n    mkdir -p \/var\/log\/mysql &amp;&amp; \\\r\n    touch \/var\/run\/mysqld\/mysqld.sock &amp;&amp; \\\r\n    touch \/var\/run\/mysqld\/mysqld.pid &amp;&amp; \\\r\n    chown -R mysql:mysql \/var\/lib\/mysql &amp;&amp; \\\r\n    chown -R mysql:mysql \/var\/run\/mysqld &amp;&amp; \\\r\n    chown -R mysql:mysql \/var\/log\/mysql &amp;&amp;\\\r\n    chmod -R 777 \/var\/run\/mysqld\/ \\\r\n    &amp;&amp; sed -i -e\"s\/^bind-address\\s*=\\s*127.0.0.1\/bind-address = 0.0.0.0\/\" \/etc\/mysql\/mysql.conf.d\/mysqld.cnf \\\r\n##install supervisor and setup supervisord.conf file\r\n    &amp;&amp; apt-get install -y supervisor nano \\\r\n    &amp;&amp; mkdir -p \/var\/log\/supervisor \r\nCMD [\"\/usr\/bin\/supervisord\"]<\/pre>\n<p>&nbsp;<\/p>\n<p>So as we have seen in our last blog as well that\u00a0Dockerfile just install packages as it is instructed to do by the commands.<\/p>\n<p>As we have mentioned earlier consider image as rest package where no services or processes are running. That is why we cannot perform any operation from Dockerfile that requires a particular service to be running.\u00a0<em><strong>As with case of database, we cannot create database from Dockerfile as mysql service is not running. For database and its user creation, we will create a bash script that will run whenever a container will launch, hence creating mentioned database and its user.<\/strong><\/em><\/p>\n<p>We are using \u201c<em>mysql.sh<\/em>\u201d as the bash script as mentioned in <em>Dockerfile<\/em>. Bash script \u201c<em>msyql.sh<\/em>\u201d resides on our host parallel to <em>Dockerfile<\/em>.<\/p>\n<p>Contents of\u00a0<em>mysql.sh<\/em>\u00a0is shown below:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\">#!\/bin\/bash\r\n\r\nset -u\r\nsleep 4\r\ndatabase_connectivity_check=no\r\nvar=1\r\nwhile [ \"$database_connectivity_check\" != \"mysql\" ]; do\r\n\/etc\/init.d\/mysql start\r\nsleep 2\r\ndatabase_connectivity_check=`mysqlshow --user=root --password=$MYSQL_ROOT_PASSWORD | grep -o mysql`\r\nif [ $var -ge 4 ]; then\r\nexit 1\r\nfi\r\nvar=$((var+1))\r\ndone\r\n\r\n\r\ndatabase_availability_check=`mysqlshow --user=root --password=$MYSQL_ROOT_PASSWORD | grep -ow \"$MYSQL_DATABASE\"`\r\n\r\nif [ \"$database_availability_check\" == \"$MYSQL_DATABASE\" ]; then\r\nexit 1\r\nelse\r\nmysql -u root -p$MYSQL_ROOT_PASSWORD -e \"grant all on *.* to 'root'@'%' identified by '$MYSQL_ROOT_PASSWORD';\"\r\nmysql -u root -p$MYSQL_ROOT_PASSWORD -e \"create database $MYSQL_DATABASE;\"\r\nmysql -u root -p$MYSQL_ROOT_PASSWORD -e \"grant all on $MYSQL_DATABASE.* to 'root'@'%' identified by '$MYSQL_ROOT_PASSWORD';\"\r\nsupervisorctl stop database_creation &amp;&amp; supervisorctl remove database_creation\r\necho \"Database $MYSQL_DATABASE created\"\r\nfi<\/pre>\n<p>&nbsp;<\/p>\n<p>Apart from <em>mysql.sh<\/em> and <em>Dockerfile,<\/em> we are also mapping <em>supervisord.conf file<\/em>. Its contents are shown below:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\">[supervisord]\r\nnodaemon=true\r\n \r\n[program:mysql]\r\ncommand=\/bin\/bash -c \"touch \/var\/run\/mysqld\/mysqld.sock;touch \/var\/run\/mysqld\/mysqld.pid;chown -R mysql:mysql \/var\/lib\/mysql;chown -R mysql:mysql \/var\/run\/mysqld;chown -R mysql:mysql \/var\/log\/mysql;chmod -R 777 \/var\/run\/mysqld\/;\/etc\/init.d\/mysql restart\"\r\n\r\n[program:database_creation]\r\ncommand=\/bin\/bash -c \"chmod a+x \/etc\/mysql.sh; \/etc\/mysql.sh\"<\/pre>\n<p>&nbsp;<\/p>\n<p>Moving on and taking a look on our cache_server directory, It contains 4 files. Dockerfile contents are shown below:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\">From ubuntu:16.04\r\n\r\nMAINTAINER Alankrit Srivastava alankrit.srivastava256@webkul.com\r\n\r\n##update server\r\n\r\nRUN apt-get update \\\r\n##install supervisor and setup supervisord.conf file\r\n&amp;&amp; apt-get install -y supervisor \\\r\n&amp;&amp; mkdir -p \/var\/log\/supervisor \\\r\n##install varnish\r\n&amp;&amp; apt-get -y install varnish \\\r\n&amp;&amp; rm \/etc\/varnish\/default.vcl \\\r\n&amp;&amp; rm \/etc\/default\/varnish \r\nEXPOSE 6082 80\r\nCMD [\"\/usr\/bin\/supervisord\"]\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>We also have server configuration file named <em>varnish<\/em> whose contents are shown below.<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\"># Configuration file for varnish\r\n#\r\n# \/etc\/init.d\/varnish expects the variables $DAEMON_OPTS, $NFILES and $MEMLOCK\r\n# to be set from this shell script fragment.\r\n#\r\n# Note: If systemd is installed, this file is obsolete and ignored.  Please see \r\n# \/usr\/share\/doc\/varnish\/examples\/varnish.systemd-drop-in.conf\r\n\r\n# Should we start varnishd at boot?  Set to \"no\" to disable.\r\nSTART=yes\r\n\r\n# Maximum number of open files (for ulimit -n)\r\nNFILES=131072\r\n\r\n# Maximum locked memory size (for ulimit -l)\r\n# Used for locking the shared memory log in memory.  If you increase log size,\r\n# you need to increase this number as well\r\nMEMLOCK=82000\r\n\r\n# Default varnish instance name is the local nodename.  Can be overridden with\r\n# the -n switch, to have more instances on a single server.\r\n# You may need to uncomment this variable for alternatives 1 and 3 below.\r\n# INSTANCE=$(uname -n)\r\n\r\n# This file contains 4 alternatives, please use only one.\r\n\r\n## Alternative 1, Minimal configuration, no VCL\r\n#\r\n# Listen on port 6081, administration on localhost:6082, and forward to\r\n# content server on localhost:8080.  Use a 1GB fixed-size cache file.\r\n#\r\n# This example uses the INSTANCE variable above, which you need to uncomment.\r\n#\r\n# DAEMON_OPTS=\"-a :6081 \\\r\n#              -T localhost:6082 \\\r\n# \t     -b localhost:8080 \\\r\n# \t     -u varnish -g varnish \\\r\n#            -S \/etc\/varnish\/secret \\\r\n# \t     -s file,\/var\/lib\/varnish\/$INSTANCE\/varnish_storage.bin,1G\"\r\n\r\n\r\n## Alternative 2, Configuration with VCL\r\n#\r\n# Listen on port 6081, administration on localhost:6082, and forward to\r\n# one content server selected by the vcl file, based on the request.\r\n#\r\nDAEMON_OPTS=\"-a :80 \\\r\n             -T localhost:6082 \\\r\n             -f \/etc\/varnish\/default.vcl \\\r\n             -S \/etc\/varnish\/secret \\\r\n             -s malloc,256m\"\r\n\r\n\r\n## Alternative 3, Advanced configuration\r\n#\r\n# This example uses the INSTANCE variable above, which you need to uncomment.\r\n#\r\n# See varnishd(1) for more information.\r\n#\r\n# # Main configuration file. You probably want to change it :)\r\n# VARNISH_VCL_CONF=\/etc\/varnish\/default.vcl\r\n#\r\n# # Default address and port to bind to\r\n# # Blank address means all IPv4 and IPv6 interfaces, otherwise specify\r\n# # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.\r\n# VARNISH_LISTEN_ADDRESS=\r\n# VARNISH_LISTEN_PORT=6081\r\n#\r\n# # Telnet admin interface listen address and port\r\n# VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1\r\n# VARNISH_ADMIN_LISTEN_PORT=6082\r\n#\r\n# # Cache file location\r\n# VARNISH_STORAGE_FILE=\/var\/lib\/varnish\/$INSTANCE\/varnish_storage.bin\r\n#\r\n# # Cache file size: in bytes, optionally using k \/ M \/ G \/ T suffix,\r\n# # or in percentage of available disk space using the % suffix.\r\n# VARNISH_STORAGE_SIZE=1G\r\n#\r\n# # File containing administration secret\r\n# VARNISH_SECRET_FILE=\/etc\/varnish\/secret\r\n# \r\n# # Backend storage specification\r\n# VARNISH_STORAGE=\"file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}\"\r\n#\r\n# # Default TTL used when the backend does not specify one\r\n# VARNISH_TTL=120\r\n#\r\n# # DAEMON_OPTS is used by the init script.  If you add or remove options, make\r\n# # sure you update this section, too.\r\n# DAEMON_OPTS=\"-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \\\r\n#              -f ${VARNISH_VCL_CONF} \\\r\n#              -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \\\r\n#              -t ${VARNISH_TTL} \\\r\n# \t       -S ${VARNISH_SECRET_FILE} \\\r\n#              -s ${VARNISH_STORAGE}\"\r\n#\r\n\r\n\r\n## Alternative 4, Do It Yourself\r\n#\r\n# DAEMON_OPTS=\"\"<\/pre>\n<p>&nbsp;<\/p>\n<p>And most importantly, our Varnish configuration language file. This VCL file is provided by Magento 2 itself and it works perfectly. Its contents are shown below.<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\">vcl 4.0;\r\n\r\nimport std;\r\n# The minimal Varnish version is 5.0\r\n# For SSL offloading, pass the following header in your proxy server or load balancer: 'X-Forwarded-Proto: https'\r\n\r\nbackend default {\r\n    .host = \"apache2\";\r\n    .port = \"8080\";\r\n    .first_byte_timeout = 600s;\r\n}\r\n\r\nacl purge {\r\n    \"localhost\";\r\n}\r\n\r\nsub vcl_recv {\r\n    if (req.method == \"PURGE\") {\r\n        if (client.ip !~ purge) {\r\n            return (synth(405, \"Method not allowed\"));\r\n        }\r\n        # To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header\r\n        # has been added to the response in your backend server config. This is used, for example, by the\r\n        # capistrano-magento2 gem for purging old content from varnish during it's deploy routine.\r\n        if (!req.http.X-Magento-Tags-Pattern &amp;&amp; !req.http.X-Pool) {\r\n            return (synth(400, \"X-Magento-Tags-Pattern or X-Pool header required\"));\r\n        }\r\n        if (req.http.X-Magento-Tags-Pattern) {\r\n          ban(\"obj.http.X-Magento-Tags ~ \" + req.http.X-Magento-Tags-Pattern);\r\n        }\r\n        if (req.http.X-Pool) {\r\n          ban(\"obj.http.X-Pool ~ \" + req.http.X-Pool);\r\n        }\r\n        return (synth(200, \"Purged\"));\r\n    }\r\n\r\n    if (req.method != \"GET\" &amp;&amp;\r\n        req.method != \"HEAD\" &amp;&amp;\r\n        req.method != \"PUT\" &amp;&amp;\r\n        req.method != \"POST\" &amp;&amp;\r\n        req.method != \"TRACE\" &amp;&amp;\r\n        req.method != \"OPTIONS\" &amp;&amp;\r\n        req.method != \"DELETE\") {\r\n          \/* Non-RFC2616 or CONNECT which is weird. *\/\r\n          return (pipe);\r\n    }\r\n\r\n    # We only deal with GET and HEAD by default\r\n    if (req.method != \"GET\" &amp;&amp; req.method != \"HEAD\") {\r\n        return (pass);\r\n    }\r\n\r\n    # Bypass shopping cart, checkout and search requests\r\n    if (req.url ~ \"\/checkout\" || req.url ~ \"\/catalogsearch\") {\r\n        return (pass);\r\n    }\r\n\r\n    # Bypass health check requests\r\n    if (req.url ~ \"\/pub\/health_check.php\") {\r\n        return (pass);\r\n    }\r\n\r\n    # Set initial grace period usage status\r\n    set req.http.grace = \"none\";\r\n\r\n    # normalize url in case of leading HTTP scheme and domain\r\n    set req.url = regsub(req.url, \"^http[s]?:\/\/\", \"\");\r\n\r\n    # collect all cookies\r\n    std.collect(req.http.Cookie);\r\n\r\n    # Compression filter. See https:\/\/www.varnish-cache.org\/trac\/wiki\/FAQ\/Compression\r\n    if (req.http.Accept-Encoding) {\r\n        if (req.url ~ \"\\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$\") {\r\n            # No point in compressing these\r\n            unset req.http.Accept-Encoding;\r\n        } elsif (req.http.Accept-Encoding ~ \"gzip\") {\r\n            set req.http.Accept-Encoding = \"gzip\";\r\n        } elsif (req.http.Accept-Encoding ~ \"deflate\" &amp;&amp; req.http.user-agent !~ \"MSIE\") {\r\n            set req.http.Accept-Encoding = \"deflate\";\r\n        } else {\r\n            # unkown algorithm\r\n            unset req.http.Accept-Encoding;\r\n        }\r\n    }\r\n\r\n    # Remove Google gclid parameters to minimize the cache objects\r\n    set req.url = regsuball(req.url,\"\\?gclid=[^&amp;]+$\",\"\"); # strips when QS = \"?gclid=AAA\"\r\n    set req.url = regsuball(req.url,\"\\?gclid=[^&amp;]+&amp;\",\"?\"); # strips when QS = \"?gclid=AAA&amp;foo=bar\"\r\n    set req.url = regsuball(req.url,\"&amp;gclid=[^&amp;]+\",\"\"); # strips when QS = \"?foo=bar&amp;gclid=AAA\" or QS = \"?foo=bar&amp;gclid=AAA&amp;bar=baz\"\r\n\r\n    # Static files caching\r\n    if (req.url ~ \"^\/(pub\/)?(media|static)\/\") {\r\n        # Static files should not be cached by default\r\n        return (pass);\r\n\r\n        # But if you use a few locales and don't use CDN you can enable caching static files by commenting previous line (#return (pass);) and uncommenting next 3 lines\r\n        #unset req.http.Https;\r\n        #unset req.http.X-Forwarded-Proto;\r\n        #unset req.http.Cookie;\r\n    }\r\n\r\n    return (hash);\r\n}\r\n\r\nsub vcl_hash {\r\n    if (req.http.cookie ~ \"X-Magento-Vary=\") {\r\n        hash_data(regsub(req.http.cookie, \"^.*?X-Magento-Vary=([^;]+);*.*$\", \"\\1\"));\r\n    }\r\n\r\n    # For multi site configurations to not cache each other's content\r\n    if (req.http.host) {\r\n        hash_data(req.http.host);\r\n    } else {\r\n        hash_data(server.ip);\r\n    }\r\n\r\n    # To make sure http users don't see ssl warning\r\n    if (req.http.X-Forwarded-Proto) {\r\n        hash_data(req.http.X-Forwarded-Proto);\r\n    }\r\n    \r\n}\r\n\r\nsub vcl_backend_response {\r\n\r\n    set beresp.grace = 3d;\r\n\r\n    if (beresp.http.content-type ~ \"text\") {\r\n        set beresp.do_esi = true;\r\n    }\r\n\r\n    if (bereq.url ~ \"\\.js$\" || beresp.http.content-type ~ \"text\") {\r\n        set beresp.do_gzip = true;\r\n    }\r\n\r\n    # cache only successfully responses and 404s\r\n    if (beresp.status != 200 &amp;&amp; beresp.status != 404) {\r\n        set beresp.ttl = 0s;\r\n        set beresp.uncacheable = true;\r\n        return (deliver);\r\n    } elsif (beresp.http.Cache-Control ~ \"private\") {\r\n        set beresp.uncacheable = true;\r\n        set beresp.ttl = 86400s;\r\n        return (deliver);\r\n    }\r\n\r\n    if (beresp.http.X-Magento-Debug) {\r\n        set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control;\r\n    }\r\n\r\n    # validate if we need to cache it and prevent from setting cookie\r\n    if (beresp.ttl &gt; 0s &amp;&amp; (bereq.method == \"GET\" || bereq.method == \"HEAD\")) {\r\n        unset beresp.http.set-cookie;\r\n    }\r\n\r\n   # If page is not cacheable then bypass varnish for 2 minutes as Hit-For-Pass\r\n   if (beresp.ttl &lt;= 0s ||\r\n        beresp.http.Surrogate-control ~ \"no-store\" ||\r\n        (!beresp.http.Surrogate-Control &amp;&amp; beresp.http.Vary == \"*\")) {\r\n        # Mark as Hit-For-Pass for the next 2 minutes\r\n        set beresp.ttl = 120s;\r\n        set beresp.uncacheable = true;\r\n    }\r\n    return (deliver);\r\n}\r\n\r\nsub vcl_deliver {\r\n    if (resp.http.X-Magento-Debug) {\r\n        if (resp.http.x-varnish ~ \" \") {\r\n            set resp.http.X-Magento-Cache-Debug = \"HIT\";\r\n            set resp.http.Grace = req.http.grace;\r\n        } else {\r\n            set resp.http.X-Magento-Cache-Debug = \"MISS\";\r\n        }\r\n    } else {\r\n        unset resp.http.Age;\r\n    }\r\n\r\n    unset resp.http.X-Magento-Debug;\r\n    unset resp.http.X-Magento-Tags;\r\n    unset resp.http.X-Powered-By;\r\n    unset resp.http.Server;\r\n    unset resp.http.X-Varnish;\r\n    unset resp.http.Via;\r\n    unset resp.http.Link;\r\n}\r\n\r\nsub vcl_hit {\r\n    if (obj.ttl &gt;= 0s) {\r\n        # Hit within TTL period\r\n        return (deliver);\r\n    }\r\n    if (std.healthy(req.backend_hint)) {\r\n        if (obj.ttl + 300s &gt; 0s) {\r\n            # Hit after TTL expiration, but within grace period\r\n            set req.http.grace = \"normal (healthy server)\";\r\n            return (deliver);\r\n        } else {\r\n            # Hit after TTL and grace expiration\r\n            return (miss);\r\n        }\r\n    } else {\r\n        # server is not healthy, retrieve from cache\r\n        set req.http.grace = \"unlimited (unhealthy server)\";\r\n        return (deliver);\r\n    }\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Take a note that we have mentioned <em>apache2 (apache container name)\u00a0<\/em>for backend host in our default.vcl file as our magento code will be mapped to apache container. Also, we also have supervisor for controlling varnish server. Its contents are shown below:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true \">[supervisord]\r\nnodaemon=true\r\n\r\n[program:varnish3.0]\r\ncommand=\/bin\/bash -c \"\/usr\/sbin\/varnishd -P \/run\/varnishd.pid -a :80 -F -T localhost:6082 -f \/etc\/varnish\/default.vcl -S \/etc\/varnish\/secret -s malloc,256m\"\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>And our last directory is\u00a0<em>magento2 directory.\u00a0<\/em>In our case, we have download Magento 2.1.6 from\u00a0<a href=\"https:\/\/magento.com\/tech-resources\/download\">https:\/\/magento.com\/tech-resources\/download<\/a>\u00a0and unarchived it in magento2 directory. <em><strong>This directory will be mapped with \/var\/www\/html directory in apache2 docker container.<\/strong><\/em><\/p>\n<p>After extracting Magento 2 files in the desired directory, our project directory setup will be completed. Now in order to build the images with docker-compose.yml file, go to project parent directory and run command,<\/p>\n<pre class=\"lang:default decode:true \">docker-compose build<\/pre>\n<p>This command will build up all three images for apache2, mysql and varnish server. To check the built images, run command,<\/p>\n<pre class=\"lang:default decode:true\">docker images<\/pre>\n<p><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/09\/Screenshot-from-2017-09-07-172831.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3382\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/09\/Screenshot-from-2017-09-07-172831.png\" alt=\"\" width=\"930\" height=\"109\" \/><\/a><\/p>\n<p>Now to run the containers as a part of single project being as mentioned in docker-compose.yml file, run the command:<\/p>\n<pre class=\"lang:default decode:true \">docker-compose up -d<\/pre>\n<p><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/09\/Screenshot-from-2017-09-07-132503.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3383\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/09\/Screenshot-from-2017-09-07-132503.png\" alt=\"\" width=\"819\" height=\"145\" \/><\/a><\/p>\n<p>Your containers will get running. To list running containers under docker-compose, run command:<\/p>\n<pre class=\"lang:default decode:true\">docker-compose ps\r\n\r\ndocker ps<\/pre>\n<p><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/09\/Screenshot-from-2017-09-07-132527.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3385\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/09\/Screenshot-from-2017-09-07-132527.png\" alt=\"\" width=\"1292\" height=\"271\" \/><\/a><\/p>\n<pre class=\"lang:default decode:true\">Now, your server setup is all ready, now hit your domain name or IP to install Magento 2. Skipping readiness check, moving forward to database configuration and admin panel configuration. If localhost doesn't work as database server host, mention your IP address.<\/pre>\n<p><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/09\/Screenshot-from-2017-09-07-132325.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3387\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/09\/Screenshot-from-2017-09-07-132325.png\" alt=\"\" width=\"555\" height=\"405\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<div id=\"crayon-59b12c9c2dd55697533504\" class=\"crayon-syntax crayon-theme-monokai crayon-font-monaco crayon-os-pc print-yes notranslate\"><\/div>\n<div id=\"crayon-59b12c9c2dd55697533504\" class=\"crayon-syntax crayon-theme-monokai crayon-font-monaco crayon-os-pc print-yes notranslate\">\n<div class=\"crayon-plain-wrap\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/09\/Screenshot-from-2017-09-06-150648-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3388\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/09\/Screenshot-from-2017-09-06-150648-1.png\" alt=\"\" width=\"1259\" height=\"641\" \/><\/a><\/div>\n<\/div>\n<div class=\"crayon-main\"><\/div>\n<div class=\"crayon-main\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/09\/Screenshot-from-2017-09-07-134146.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3389\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/09\/Screenshot-from-2017-09-07-134146.png\" alt=\"\" width=\"794\" height=\"302\" \/><\/a><\/div>\n<div class=\"crayon-main\"><\/div>\n<p class=\"crayon-main\">Then proceed further and install the Magento 2.<\/p>\n<p class=\"crayon-main\">After successful installation, we need to configure Magento 2 from admin panel to use Varnish Cache instead of its built-in cache. So, login to your admin panel. Go to STORES\u00a0&#8211;&gt; Configuration &#8211;&gt; ADVANCED &#8211;&gt; System &#8211;&gt; Full Page Cache as,<\/p>\n<div class=\"crayon-main\"><\/div>\n<div class=\"crayon-main\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/09\/Screenshot-from-2017-09-07-135631.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3390\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/09\/Screenshot-from-2017-09-07-135631.png\" alt=\"\" width=\"1192\" height=\"522\" \/><\/a><\/div>\n<div class=\"crayon-main\"><\/div>\n<div class=\"crayon-main\"><\/div>\n<p class=\"crayon-main\">Select Varnish Cache in Caching Application and scroll down,<\/p>\n<div class=\"crayon-main\"><\/div>\n<div class=\"crayon-main\"><\/div>\n<div class=\"crayon-main\"><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/09\/Screenshot-from-2017-09-07-135719.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3391\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/09\/Screenshot-from-2017-09-07-135719.png\" alt=\"\" width=\"1276\" height=\"581\" \/><\/a><\/div>\n<div class=\"crayon-main\"><\/div>\n<div class=\"crayon-main\"><\/div>\n<div class=\"crayon-main\"><\/div>\n<p class=\"crayon-main\">\u00a0Mention the backend host, backend port and Access list. As we already have our VCL file &#8220;default.vcl&#8221;, we don&#8217;t need to export it. Now, clear all the cache from Magento admin. Now, Varnish Server has been integrated with our Magento 2 store.<\/p>\n<p>As \u00a0you might have noticed that we are running apache2 server (our backend server) on port 8080 and Varnish cache server \u00a0on port 80. So here&#8217;s how Varnish is working: Varnish acts a reverse proxy server typically sits at port 80 and directs client requests to the back-end apache2 server at port 8080. Whenever a client makes a request, Varnish server checks the content within the cache and incase data not found it send the request to backend server and fetch the content to client and keep a copy of the data as cache. When the same request is made, Varnish does not bother apache2 server, it just fetch the data from the cache. It provides an additional level of abstraction and control to ensure the smooth flow of network traffic between clients and servers.<\/p>\n<p>To check if varnish is working or not, go to your varnish container,<\/p>\n<pre class=\"lang:default decode:true \">docker exec -ti varnish bash<\/pre>\n<p>Now, run command:<\/p>\n<pre class=\"lang:default decode:true \">varnishhist<\/pre>\n<p><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/09\/Screenshot-from-2017-09-07-135849.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3414\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/09\/Screenshot-from-2017-09-07-135849.png\" alt=\"\" width=\"1272\" height=\"579\" \/><\/a><\/p>\n<p>And hit your domain URL, when first time you hit it you will see &#8216;#&#8217; on the terminal representing cache miss as first request is forwarded to main server. Next time as you hit the browser, you will see &#8216;|&#8217; increasing and &#8216;#&#8217; decreasing representing cache hits.<\/p>\n<p>So far we have discussed how to setup Magento 2 and integrate it with Varnish Cache server using docker-compose on multiple docker container architecture. Please refer to repository <a href=\"https:\/\/github.com\/webkul\/magento2-varnish-docker-compose\">https:\/\/github.com\/webkul\/magento2-varnish-docker-compose<\/a> to deploy same architecture.<\/p>\n<p>In our next blog we will add an extra layer in our current architecture by integrating redis-server with Magento 2.<\/p>\n<div class=\"crayon-main\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In our last\u00a0blog,\u00a0after being introduced to docker-compose, we had discussed the deployment of multi-container architecture <a class=\"text-primary\" title=\"read more\" href=\"https:\/\/cloudkul.com\/blog\/magento-2-and-varnish-cache-integration-with-docker-compose\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":7,"featured_media":3401,"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>Magento 2 and Varnish Cache Integration With Docker-Compose - Cloudkul<\/title>\n<meta name=\"description\" content=\"As we are still on our multi-container docker architecture, we will be using separate containers for apache2 server, mysql-server and varnish cache server for its integration with Magento 2 on Ubuntu 14.04. As it separate containers will require inter-linking with each other, we will be docker-compose tool to achieve this architecture. The parent directory holding all the files\/directories will be considered as the project name. Custom project name can also be in set docker-compose.yml file. Here we are creating separate directories for apache2, mysql server and varnish cache server setup that hold their Dockerfile(s) and their associated volumes.\" \/>\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\/magento-2-and-varnish-cache-integration-with-docker-compose\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Magento 2 and Varnish Cache Integration With Docker-Compose - Cloudkul\" \/>\n<meta property=\"og:description\" content=\"As we are still on our multi-container docker architecture, we will be using separate containers for apache2 server, mysql-server and varnish cache server for its integration with Magento 2 on Ubuntu 14.04. As it separate containers will require inter-linking with each other, we will be docker-compose tool to achieve this architecture. The parent directory holding all the files\/directories will be considered as the project name. Custom project name can also be in set docker-compose.yml file. Here we are creating separate directories for apache2, mysql server and varnish cache server setup that hold their Dockerfile(s) and their associated volumes.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudkul.com\/blog\/magento-2-and-varnish-cache-integration-with-docker-compose\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudkul\" \/>\n<meta property=\"article:published_time\" content=\"2017-09-07T12:48:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-07-17T09:22:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/09\/download-2.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\/magento-2-and-varnish-cache-integration-with-docker-compose\/\",\"url\":\"https:\/\/cloudkul.com\/blog\/magento-2-and-varnish-cache-integration-with-docker-compose\/\",\"name\":\"Magento 2 and Varnish Cache Integration With Docker-Compose - Cloudkul\",\"isPartOf\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\"},\"datePublished\":\"2017-09-07T12:48:12+00:00\",\"dateModified\":\"2018-07-17T09:22:03+00:00\",\"author\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/fc06bfd7f18d9a606dd94062d205af16\"},\"description\":\"As we are still on our multi-container docker architecture, we will be using separate containers for apache2 server, mysql-server and varnish cache server for its integration with Magento 2 on Ubuntu 14.04. As it separate containers will require inter-linking with each other, we will be docker-compose tool to achieve this architecture. The parent directory holding all the files\/directories will be considered as the project name. Custom project name can also be in set docker-compose.yml file. Here we are creating separate directories for apache2, mysql server and varnish cache server setup that hold their Dockerfile(s) and their associated volumes.\",\"breadcrumb\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/magento-2-and-varnish-cache-integration-with-docker-compose\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudkul.com\/blog\/magento-2-and-varnish-cache-integration-with-docker-compose\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudkul.com\/blog\/magento-2-and-varnish-cache-integration-with-docker-compose\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Magento 2 and Varnish Cache Integration With Docker-Compose\"}]},{\"@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":"Magento 2 and Varnish Cache Integration With Docker-Compose - Cloudkul","description":"As we are still on our multi-container docker architecture, we will be using separate containers for apache2 server, mysql-server and varnish cache server for its integration with Magento 2 on Ubuntu 14.04. As it separate containers will require inter-linking with each other, we will be docker-compose tool to achieve this architecture. The parent directory holding all the files\/directories will be considered as the project name. Custom project name can also be in set docker-compose.yml file. Here we are creating separate directories for apache2, mysql server and varnish cache server setup that hold their Dockerfile(s) and their associated volumes.","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\/magento-2-and-varnish-cache-integration-with-docker-compose\/","og_locale":"en_US","og_type":"article","og_title":"Magento 2 and Varnish Cache Integration With Docker-Compose - Cloudkul","og_description":"As we are still on our multi-container docker architecture, we will be using separate containers for apache2 server, mysql-server and varnish cache server for its integration with Magento 2 on Ubuntu 14.04. As it separate containers will require inter-linking with each other, we will be docker-compose tool to achieve this architecture. The parent directory holding all the files\/directories will be considered as the project name. Custom project name can also be in set docker-compose.yml file. Here we are creating separate directories for apache2, mysql server and varnish cache server setup that hold their Dockerfile(s) and their associated volumes.","og_url":"https:\/\/cloudkul.com\/blog\/magento-2-and-varnish-cache-integration-with-docker-compose\/","og_site_name":"Cloudkul","article_published_time":"2017-09-07T12:48:12+00:00","article_modified_time":"2018-07-17T09:22:03+00:00","og_image":[{"width":848,"height":422,"url":"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/09\/download-2.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\/magento-2-and-varnish-cache-integration-with-docker-compose\/","url":"https:\/\/cloudkul.com\/blog\/magento-2-and-varnish-cache-integration-with-docker-compose\/","name":"Magento 2 and Varnish Cache Integration With Docker-Compose - Cloudkul","isPartOf":{"@id":"https:\/\/cloudkul.com\/blog\/#website"},"datePublished":"2017-09-07T12:48:12+00:00","dateModified":"2018-07-17T09:22:03+00:00","author":{"@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/fc06bfd7f18d9a606dd94062d205af16"},"description":"As we are still on our multi-container docker architecture, we will be using separate containers for apache2 server, mysql-server and varnish cache server for its integration with Magento 2 on Ubuntu 14.04. As it separate containers will require inter-linking with each other, we will be docker-compose tool to achieve this architecture. The parent directory holding all the files\/directories will be considered as the project name. Custom project name can also be in set docker-compose.yml file. Here we are creating separate directories for apache2, mysql server and varnish cache server setup that hold their Dockerfile(s) and their associated volumes.","breadcrumb":{"@id":"https:\/\/cloudkul.com\/blog\/magento-2-and-varnish-cache-integration-with-docker-compose\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudkul.com\/blog\/magento-2-and-varnish-cache-integration-with-docker-compose\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cloudkul.com\/blog\/magento-2-and-varnish-cache-integration-with-docker-compose\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Magento 2 and Varnish Cache Integration With Docker-Compose"}]},{"@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\/3359"}],"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=3359"}],"version-history":[{"count":39,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/3359\/revisions"}],"predecessor-version":[{"id":3735,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/3359\/revisions\/3735"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/media\/3401"}],"wp:attachment":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/media?parent=3359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/categories?post=3359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/tags?post=3359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}