{"id":2670,"date":"2018-10-30T09:50:48","date_gmt":"2018-10-30T07:50:48","guid":{"rendered":"http:\/\/hasselba.ch\/blog\/?p=2670"},"modified":"2018-11-02T08:57:52","modified_gmt":"2018-11-02T06:57:52","slug":"node-js-domino-db-docker","status":"publish","type":"post","link":"https:\/\/hasselba.ch\/blog\/?p=2670","title":{"rendered":"node.js, domino-db &#038; Docker"},"content":{"rendered":"<p>Here is an example to create a express application with the new <em>domino-db<\/em> npm module and run it in a docker container. Requirements are that node.js &amp; Docker is installed. Everything is done in the command line and a text editor.<\/p>\n<p>1. Install <a href=\"https:\/\/expressjs.com\/de\/starter\/generator.html\" target=\"_blank\" rel=\"noopener\">Express application generator<\/a><\/p>\n<pre><code>npm install express-generator -g<\/code><\/pre>\n<p>2. Create a fresh application with <em>stylus<\/em> engine<\/p>\n<pre><code>express -c stylus domino-express<\/code><\/pre>\n<p>3. Go to the newly created folder<\/p>\n<pre><code>cd domino-express\/<\/code><\/pre>\n<p>4. Create a folder for the application<\/p>\n<pre><code>md app\/<\/code><\/pre>\n<p>5. Copy all files to the <em>app<\/em> folder, only <em>package.json<\/em> should be left<\/p>\n<p>6. Copy the <em>domino-domino-db-1.0.0-package<\/em> folder into the project folder<\/p>\n<p>7. Create a file <em>.dockerignore<\/em> and with the following content:<\/p>\n<pre><code>node_modules\r\nnpm-debug.log<\/code><\/pre>\n<p>8. Create the <em>Dockerfile<\/em> with the following content:<\/p>\n<pre><code>FROM node:8\r\n\r\n# Create app directory\r\nWORKDIR \/usr\/src\/app\r\n\r\n# Install app dependencies\r\n# A wildcard is used to ensure both package.json AND package-lock.json are copied\r\n# where available (npm@5+)\r\nCOPY package*.json .\/\r\n\r\n# create a folder for the local domino-db package\r\nRUN mkdir -p \/src\r\nCOPY .\/domino-domino-db-1.0.0-package \/src\/domino-domino-db-1.0.0-package\r\n\r\n# install &amp; rebuild\r\nRUN npm install\r\nRUN npm rebuild\r\n\r\n# If you are building your code for production\r\n# RUN npm install --only=production\r\n\r\n# Bundle app source\r\nCOPY .\/app .\r\n\r\nEXPOSE 3000\r\nCMD [ \"npm\", \"start\" ]<\/code><\/pre>\n<p>9. The directory structure should look like this:<\/p>\n<pre><code>\/domino-express\r\n   |-app\r\n      |-...\r\n   |-domino-domino-db-1.0.0-package\r\n      |-...\r\n   |-.dockerignore\r\n   |-Dockerfile\r\n   |-package.json<\/code><\/pre>\n<p>10. Add <em>domino-db<\/em> to <em>package.json<\/em><\/p>\n<pre><code>{\r\n  \"name\": \"domino-express\",\r\n  \"version\": \"0.0.0\",\r\n  \"private\": true,\r\n  \"scripts\": {\r\n    \"start\": \"node .\/bin\/www\"\r\n  },\r\n  \"dependencies\": {\r\n    \"cookie-parser\": \"~1.4.3\",\r\n    \"debug\": \"~2.6.9\",\r\n    \"express\": \"~4.16.0\",\r\n    \"http-errors\": \"~1.6.2\",\r\n    \"jade\": \"~1.11.0\",\r\n    \"morgan\": \"~1.9.0\",\r\n    \"stylus\": \"0.54.5\",\r\n    <strong>\"@domino\/domino-db\": \"file:\/src\/domino-domino-db-1.0.0-package\"<\/strong>\r\n  }\r\n}<\/code><\/pre>\n<p>11. Build the docker container (replace username with your docker id)<\/p>\n<pre><code>docker build -t {username}\/domino-express .<\/code><\/pre>\n<p>12. Start the container<\/p>\n<pre><code>docker run -p 3000:3000 -d -it {username}\/domino-express<\/code><\/pre>\n<p>13. Open it in your browser =&gt; http:\/\/localhost:3000<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is an example to create a express application with the new domino-db npm module and run it in a docker container. Requirements are that node.js &amp; Docker is installed. Everything is done in the command line and a text &hellip; <a href=\"https:\/\/hasselba.ch\/blog\/?p=2670\">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":[139,9,131],"tags":[7,133,132],"class_list":["post-2670","post","type-post","status-publish","format-standard","hentry","category-es6","category-javascript","category-node-js","tag-domino","tag-express","tag-node-js"],"_links":{"self":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2670","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=2670"}],"version-history":[{"count":5,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2670\/revisions"}],"predecessor-version":[{"id":2676,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2670\/revisions\/2676"}],"wp:attachment":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2670"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2670"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2670"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}