{"id":2704,"date":"2018-11-05T09:15:44","date_gmt":"2018-11-05T07:15:44","guid":{"rendered":"http:\/\/hasselba.ch\/blog\/?p=2704"},"modified":"2018-11-05T09:15:44","modified_gmt":"2018-11-05T07:15:44","slug":"node-js-domino-db-docker-5-memcached","status":"publish","type":"post","link":"https:\/\/hasselba.ch\/blog\/?p=2704","title":{"rendered":"node.js, domino-db &#038; Docker (5): memcached"},"content":{"rendered":"<p>To use <a href=\"https:\/\/www.memcached.org\/\" target=\"_blank\" rel=\"noopener\">memcached<\/a> in our Docker container, we have to modify the existing <a href=\"https:\/\/hasselba.ch\/blog\/?p=2670\" target=\"_blank\" rel=\"noopener\">Dockerfile<\/a> a little bit. First it is required to install memcached in the container itself, and then it is required to change the CMD command to start the service and our express application.<\/p>\n<p>1. Create a folder <em>\/conf<\/em> in the project folder<\/p>\n<p>2. Create a file <em>memcached.conf<\/em> in this folder with the following content:<\/p>\n<pre><code># Memory: 256 MB\r\n-m 256\r\n\r\n# Port to use\r\n-p 11211\r\n\r\n# User for the service\r\n-u memcache\r\n\r\n# Listening IP Adress \r\n-l 127.0.0.1<\/code><\/pre>\n<p>3. Create a script <em>startup.sh<\/em> in the newly created folder:<\/p>\n<pre><code>#!\/bin\/bash\r\nservice memcached start\r\nnpm start<\/code><\/pre>\n<p>4. Modify the Dockerfile to install <em>memcached<\/em><em><br \/>\n<\/em><\/p>\n<pre><code># install memcached\r\nRUN apt-get update\r\nRUN apt-get install -y memcached\r\n<\/code><\/pre>\n<p>5. Copy <em>the startup.sh<\/em> script and the <em>memcached.conf<\/em><\/p>\n<pre><code>COPY .\/conf\/memcached.conf \/etc\r\nCOPY .\/conf\/startup.sh .\r\nRUN chmod +x \/usr\/src\/app\/startup.sh<\/code><\/pre>\n<p>6. Change the <em>CMD<\/em> to use the <em>startup.sh<\/em> script<\/p>\n<pre><code>CMD [ \".\/startup.sh\" ]<\/code><\/pre>\n<p>The reason for the startup script is that in Docker containers the services are disabled by default, so we need to start the service by our own. Also, only one CMD command is allowed, so we have to use a script.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To use memcached in our Docker container, we have to modify the existing Dockerfile a little bit. First it is required to install memcached in the container itself, and then it is required to change the CMD command to start &hellip; <a href=\"https:\/\/hasselba.ch\/blog\/?p=2704\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[141,131],"tags":[142,143,132],"class_list":["post-2704","post","type-post","status-publish","format-standard","hentry","category-docker","category-node-js","tag-docker","tag-memcached","tag-node-js"],"_links":{"self":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2704","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2704"}],"version-history":[{"count":4,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2704\/revisions"}],"predecessor-version":[{"id":2710,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2704\/revisions\/2710"}],"wp:attachment":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2704"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2704"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2704"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}