{"id":1704,"date":"2023-02-15T14:19:47","date_gmt":"2023-02-15T08:49:47","guid":{"rendered":"https:\/\/www.prasadk.com\/my-press\/?p=1704"},"modified":"2023-02-16T15:25:09","modified_gmt":"2023-02-16T09:55:09","slug":"create-docker-file","status":"publish","type":"post","link":"https:\/\/www.prasadk.com\/my-press\/create-docker-file\/","title":{"rendered":"A Sample Dockerfile (UI App) using nginx server"},"content":{"rendered":"<div class=\"dm-code-snippet dark default  dm-normal-version\" style=\"background-color:#abb8c3;\" snippet-height=\"\">\n\t\t\t<div class=\"control-language\">\n                <div class=\"dm-buttons\">\n                    <div class=\"dm-buttons-left\">\n                        <div class=\"dm-button-snippet red-button\"><\/div>\n                        <div class=\"dm-button-snippet orange-button\"><\/div>\n                        <div class=\"dm-button-snippet green-button\"><\/div>\n                    <\/div>\n                    <div class=\"dm-buttons-right\">\n                        <a id=\"dm-copy-raw-code\">\n                        <span class=\"dm-copy-text\">Copy Code<\/span>\n                        <span class=\"dm-copy-confirmed\" style=\"display:none\">Copied<\/span>\n                        <span class=\"dm-error-message\" style=\"display:none\">Use a different Browser<\/span><\/a>\n                    <\/div>\n                <\/div>\n                <pre class=\"no-line-numbers\"><code id=\"dm-code-raw\" class=\"no-wrap language-shell\"><\/p>\n<pre class=\"dm-pre-admin-side\"># Stage 1\r\n\r\nFROM node:14.15.4 as node\r\n\r\nWORKDIR \/mydir\r\n\r\nCOPY . .\r\n\r\nRUN npm install\r\n\r\nRUN npm run build --prod\r\n\r\n# Stage 2\r\n\r\nFROM nginx:alpine\r\n\r\nCOPY --from=node mydir\/dist\/uiapp \/usr\/share\/nginx\/html<\/pre>\n<p><\/code><\/pre>\n\t\t\t<\/div>\n        <\/div>\n<p>This Dockerfile is a multi-stage build that is used to build and deploy a Node.js application with a NGINX web server in a container.<\/p>\n<h5>This file has 2 stages<\/h5>\n<p>:<\/p>\n<ol>\n<li>This stage uses a Node.js base image (starts with a Node.js 14.15.4 base image) to set up the build environment for the application.<\/li>\n<\/ol>\n<p>Sets the working directory to &#8220;\/mydir&#8221;.<\/p>\n<p>It copies the application code into the container (copies the current directory into the container) and installs dependencies using npm.<\/p>\n<p>Then runs the build command to create a production build of the application in the \/mydir\/dist directory.<\/p>\n<ol start=\"2\">\n<li>This stage uses an NGINX base image to create a production image of the application.<\/li>\n<\/ol>\n<p>It copies the production build created in Stage 1 from the \/mydir\/dist directory to the NGINX web server&#8217;s default directory for serving static content, \/usr\/share\/nginx\/html.<\/p>\n<p>The resulting Docker image will contain the NGINX web server and the built production files of the Node.js application. When we run the container, NGINX will serve the static files of the application.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This Dockerfile is a multi-stage build that is used to build and deploy a Node.js application with a NGINX web server in a container. This [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":1735,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0},"categories":[216,225,217,7],"tags":[228,229,224,226,227],"_links":{"self":[{"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/posts\/1704"}],"collection":[{"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/comments?post=1704"}],"version-history":[{"count":5,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/posts\/1704\/revisions"}],"predecessor-version":[{"id":1736,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/posts\/1704\/revisions\/1736"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/media\/1735"}],"wp:attachment":[{"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/media?parent=1704"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/categories?post=1704"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/tags?post=1704"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}