Docker Mini project : Containerize an amazing Node JS Portfolio App

Swastik Mukherjee
16 min readFeb 9, 2022

In this article we will be building a very simple yet amazing node js server app that serves your portfolio website with few lines of code. Then we will Containerize the app. Please note that the blog focuses on the Containerizing part more, rather paying attention to the codes for node. let’s jump into the first step to prepare our server.

Step 1 : Create your portfolio Website within few seconds

You don’t know how to code HTML/CSS or any web framework to build the site? Don’t worry chap, follow this link for a readymade template. Feel free to choose if you like any other template and play with it. Once your HTML/CSS format is ready with the below code lets create our node js server with just few lines of code.

<!DOCTYPE html><html><title>W3.CSS Template</title><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"><style>body,h1,h2,h3,h4,h5,h6 {font-family: "Lato", sans-serif;}body, html {height: 100%;color: #777;line-height: 1.8;}/* Create a Parallax Effect */.bgimg-1, .bgimg-2, .bgimg-3 {background-attachment: fixed;background-position: center;background-repeat: no-repeat;background-size: cover;}/* First image (Logo. Full height) */.bgimg-1 {background-image: url('https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=');min-height: 100%;}/* Second image (Portfolio) */.bgimg-2 {background-image: url("https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=");min-height: 400px;}/* Third image (Contact) */.bgimg-3 {background-image: url("https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=");min-height: 400px;}.w3-wide {letter-spacing: 10px;}.w3-hover-opacity {cursor: pointer;}/* Turn off parallax scrolling for tablets and phones */@media only screen and (max-device-width: 1600px) {.bgimg-1, .bgimg-2, .bgimg-3 {background-attachment: scroll;min-height: 400px;}}</style><body><!-- Navbar (sit on top) --><div class="w3-top"><div class="w3-bar" id="myNavbar"><a class="w3-bar-item w3-button w3-hover-black w3-hide-medium w3-hide-large w3-right" href="javascript:void(0);" onclick="toggleFunction()" title="Toggle Navigation Menu"><i class="fa fa-bars"></i></a><a href="#home" class="w3-bar-item w3-button">HOME</a><a href="#about" class="w3-bar-item w3-button w3-hide-small"><i class="fa fa-user"></i> ABOUT</a><a href="#portfolio" class="w3-bar-item w3-button w3-hide-small"><i class="fa fa-th"></i> PORTFOLIO</a><a href="#contact" class="w3-bar-item w3-button w3-hide-small"><i class="fa fa-envelope"></i> CONTACT</a><a href="#" class="w3-bar-item w3-button w3-hide-small w3-right w3-hover-red"><i class="fa fa-search"></i></a></div><!-- Navbar on small screens --><div id="navDemo" class="w3-bar-block w3-white w3-hide w3-hide-large w3-hide-medium"><a href="#about" class="w3-bar-item w3-button" onclick="toggleFunction()">ABOUT</a><a href="#portfolio" class="w3-bar-item w3-button" onclick="toggleFunction()">PORTFOLIO</a><a href="#contact" class="w3-bar-item w3-button" onclick="toggleFunction()">CONTACT</a><a href="#" class="w3-bar-item w3-button">SEARCH</a></div></div><!-- First Parallax Image with Logo Text --><div class="bgimg-1 w3-display-container w3-opacity-min" id="home"><div class="w3-display-middle" style="white-space:nowrap;"><span class="w3-center w3-padding-large w3-black w3-xlarge w3-wide w3-animate-opacity">MY <span class="w3-hide-small">WEBSITE</span> LOGO</span></div></div><!-- Container (About Section) --><div class="w3-content w3-container w3-padding-64" id="about"><h3 class="w3-center">ABOUT ME</h3><p class="w3-center"><em>I love photography</em></p><p>We have created a fictional "personal" website/blog, and our fictional character is a hobby photographer. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpaqui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p><div class="w3-row"><div class="w3-col m6 w3-center w3-padding-large"><p><b><i class="fa fa-user w3-margin-right"></i>My Name</b></p><br><img src="https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=" class="w3-round w3-image w3-opacity w3-hover-opacity-off" alt="Photo of Me" width="500" height="333"></div><!-- Hide this text on small devices --><div class="w3-col m6 w3-hide-small w3-padding-large"><p>Welcome to my website. I am lorem ipsum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute iruredolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod temporincididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p></div></div><p class="w3-large w3-center w3-padding-16">Im really good at:</p><p class="w3-wide"><i class="fa fa-camera"></i>Photography</p><div class="w3-light-grey"><div class="w3-container w3-padding-small w3-dark-grey w3-center" style="width:90%">90%</div></div><p class="w3-wide"><i class="fa fa-laptop"></i>Web Design</p><div class="w3-light-grey"><div class="w3-container w3-padding-small w3-dark-grey w3-center" style="width:85%">85%</div></div><p class="w3-wide"><i class="fa fa-photo"></i>Photoshop</p><div class="w3-light-grey"><div class="w3-container w3-padding-small w3-dark-grey w3-center" style="width:75%">75%</div></div></div><div class="w3-row w3-center w3-dark-grey w3-padding-16"><div class="w3-quarter w3-section"><span class="w3-xlarge">14+</span><br>Partners</div><div class="w3-quarter w3-section"><span class="w3-xlarge">55+</span><br>Projects Done</div><div class="w3-quarter w3-section"><span class="w3-xlarge">89+</span><br>Happy Clients</div><div class="w3-quarter w3-section"><span class="w3-xlarge">150+</span><br>Meetings</div></div><!-- Second Parallax Image with Portfolio Text --><div class="bgimg-2 w3-display-container w3-opacity-min"><div class="w3-display-middle"><span class="w3-xxlarge w3-text-white w3-wide">PORTFOLIO</span></div></div><!-- Container (Portfolio Section) --><div class="w3-content w3-container w3-padding-64" id="portfolio"><h3 class="w3-center">MY WORK</h3><p class="w3-center"><em>Here are some of my latest lorem work ipsum tipsum.<br> Click on the images to make them bigger</em></p><br><!-- Responsive Grid. Four columns on tablets, laptops and desktops. Will stack on mobile devices/small screens (100% width) --><div class="w3-row-padding w3-center"><div class="w3-col m3"><img src="https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=" style="width:100%" onclick="onClick(this)" class="w3-hover-opacity" alt="The mist over the mountains"></div><div class="w3-col m3"><img src="https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=" style="width:100%" onclick="onClick(this)" class="w3-hover-opacity" alt="Coffee beans"></div><div class="w3-col m3"><img src="https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=" style="width:100%" onclick="onClick(this)" class="w3-hover-opacity" alt="Bear closeup"></div><div class="w3-col m3"><img src="https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=" style="width:100%" onclick="onClick(this)" class="w3-hover-opacity" alt="Quiet ocean"></div></div><div class="w3-row-padding w3-center w3-section"><div class="w3-col m3"><img src="https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=" style="width:100%" onclick="onClick(this)" class="w3-hover-opacity" alt="The mist"></div><div class="w3-col m3"><img src="https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=" style="width:100%" onclick="onClick(this)" class="w3-hover-opacity" alt="My beloved typewriter"></div><div class="w3-col m3"><img src="https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=" style="width:100%" onclick="onClick(this)" class="w3-hover-opacity" alt="Empty ghost train"></div><div class="w3-col m3"><img src="https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=" style="width:100%" onclick="onClick(this)" class="w3-hover-opacity" alt="Sailing"></div><button class="w3-button w3-padding-large w3-light-grey" style="margin-top:64px">LOAD MORE</button></div></div><!-- Modal for full size images on click--><div id="modal01" class="w3-modal w3-black" onclick="this.style.display='none'"><span class="w3-button w3-large w3-black w3-display-topright" title="Close Modal Image"><i class="fa fa-remove"></i></span><div class="w3-modal-content w3-animate-zoom w3-center w3-transparent w3-padding-64"><img id="img01" class="w3-image"><p id="caption" class="w3-opacity w3-large"></p></div></div><!-- Third Parallax Image with Portfolio Text --><div class="bgimg-3 w3-display-container w3-opacity-min"><div class="w3-display-middle"><span class="w3-xxlarge w3-text-white w3-wide">CONTACT</span></div></div><!-- Container (Contact Section) --><div class="w3-content w3-container w3-padding-64" id="contact"><h3 class="w3-center">WHERE I WORK</h3><p class="w3-center"><em>I'd love your feedback!</em></p><div class="w3-row w3-padding-32 w3-section"><div class="w3-col m4 w3-container"><img src="https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=" class="w3-image w3-round" style="width:100%"></div><div class="w3-col m8 w3-panel"><div class="w3-large w3-margin-bottom"><i class="fa fa-map-marker fa-fw w3-hover-text-black w3-xlarge w3-margin-right"></i> Chicago, US<br><i class="fa fa-phone fa-fw w3-hover-text-black w3-xlarge w3-margin-right"></i> Phone: +00 151515<br><i class="fa fa-envelope fa-fw w3-hover-text-black w3-xlarge w3-margin-right"></i> Email: mail@mail.com<br></div><p>Swing by for a cup of <i class="fa fa-coffee"></i>, or leave me a note:</p><form action="/action_page.php" target="_blank"><div class="w3-row-padding" style="margin:0 -16px 8px -16px"><div class="w3-half"><input class="w3-input w3-border" type="text" placeholder="Name" required name="Name"></div><div class="w3-half"><input class="w3-input w3-border" type="text" placeholder="Email" required name="Email"></div></div><input class="w3-input w3-border" type="text" placeholder="Message" required name="Message"><button class="w3-button w3-black w3-right w3-section" type="submit"><i class="fa fa-paper-plane"></i> SEND MESSAGE</button></form></div></div></div><!-- Footer --><footer class="w3-center w3-black w3-padding-64 w3-opacity w3-hover-opacity-off"><a href="#home" class="w3-button w3-light-grey"><i class="fa fa-arrow-up w3-margin-right"></i>To the top</a><div class="w3-xlarge w3-section"><i class="fa fa-facebook-official w3-hover-opacity"></i><i class="fa fa-instagram w3-hover-opacity"></i><i class="fa fa-snapchat w3-hover-opacity"></i><i class="fa fa-pinterest-p w3-hover-opacity"></i><i class="fa fa-twitter w3-hover-opacity"></i><i class="fa fa-linkedin w3-hover-opacity"></i></div><p>Powered by <a href="https://www.w3schools.com/w3css/default.asp" title="W3.CSS" target="_blank" class="w3-hover-text-green">w3.css</a></p></footer><script>// Modal Image Galleryfunction onClick(element) {document.getElementById("img01").src = element.src;document.getElementById("modal01").style.display = "block";var captionText = document.getElementById("caption");captionText.innerHTML = element.alt;}// Change style of navbar on scrollwindow.onscroll = function() {myFunction()};function myFunction() {var navbar = document.getElementById("myNavbar");if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {navbar.className = "w3-bar" + " w3-card" + " w3-animate-top" + " w3-white";} else {navbar.className = navbar.className.replace(" w3-card w3-animate-top w3-white", "");}}// Used to toggle the menu on small screens when clicking on the menu buttonfunction toggleFunction() {var x = document.getElementById("navDemo");if (x.className.indexOf("w3-show") == -1) {x.className += " w3-show";} else {x.className = x.className.replace(" w3-show", "");}}</script></body></html>

Step 2: Prepare your node js Server in just few lines of code

Don’t worry if you don’t know node. In a life of DevOps, there will be frequent instances when you will be provided with the code, you just need to build image from it. Let’s create the server.js file and stuff the below with HTML/CSS embedded in it.

const express = require('express');const app = express();app.get('/', (req, res) => {res.send(`<!DOCTYPE html><html><title>W3.CSS Template</title><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"><style>body,h1,h2,h3,h4,h5,h6 {font-family: "Lato", sans-serif;}body, html {height: 100%;color: #777;line-height: 1.8;}/* Create a Parallax Effect */.bgimg-1, .bgimg-2, .bgimg-3 {background-attachment: fixed;background-position: center;background-repeat: no-repeat;background-size: cover;}/* First image (Logo. Full height) */.bgimg-1 {background-image: url('https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=');min-height: 100%;}/* Second image (Portfolio) */.bgimg-2 {background-image: url("https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=");min-height: 400px;}/* Third image (Contact) */.bgimg-3 {background-image: url("https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=");min-height: 400px;}.w3-wide {letter-spacing: 10px;}.w3-hover-opacity {cursor: pointer;}/* Turn off parallax scrolling for tablets and phones */@media only screen and (max-device-width: 1600px) {.bgimg-1, .bgimg-2, .bgimg-3 {background-attachment: scroll;min-height: 400px;}}</style><body><!-- Navbar (sit on top) --><div class="w3-top"><div class="w3-bar" id="myNavbar"><a class="w3-bar-item w3-button w3-hover-black w3-hide-medium w3-hide-large w3-right" href="javascript:void(0);" onclick="toggleFunction()" title="Toggle Navigation Menu"><i class="fa fa-bars"></i></a><a href="#home" class="w3-bar-item w3-button">HOME</a><a href="#about" class="w3-bar-item w3-button w3-hide-small"><i class="fa fa-user"></i> ABOUT</a><a href="#portfolio" class="w3-bar-item w3-button w3-hide-small"><i class="fa fa-th"></i> PORTFOLIO</a><a href="#contact" class="w3-bar-item w3-button w3-hide-small"><i class="fa fa-envelope"></i> CONTACT</a><a href="#" class="w3-bar-item w3-button w3-hide-small w3-right w3-hover-red"><i class="fa fa-search"></i></a></div><!-- Navbar on small screens --><div id="navDemo" class="w3-bar-block w3-white w3-hide w3-hide-large w3-hide-medium"><a href="#about" class="w3-bar-item w3-button" onclick="toggleFunction()">ABOUT</a><a href="#portfolio" class="w3-bar-item w3-button" onclick="toggleFunction()">PORTFOLIO</a><a href="#contact" class="w3-bar-item w3-button" onclick="toggleFunction()">CONTACT</a><a href="#" class="w3-bar-item w3-button">SEARCH</a></div></div><!-- First Parallax Image with Logo Text --><div class="bgimg-1 w3-display-container w3-opacity-min" id="home"><div class="w3-display-middle" style="white-space:nowrap;"><span class="w3-center w3-padding-large w3-black w3-xlarge w3-wide w3-animate-opacity">MY <span class="w3-hide-small">WEBSITE</span> LOGO</span></div></div><!-- Container (About Section) --><div class="w3-content w3-container w3-padding-64" id="about"><h3 class="w3-center">ABOUT ME</h3><p class="w3-center"><em>I love photography</em></p><p>We have created a fictional "personal" website/blog, and our fictional character is a hobby photographer. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpaqui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p><div class="w3-row"><div class="w3-col m6 w3-center w3-padding-large"><p><b><i class="fa fa-user w3-margin-right"></i>My Name</b></p><br><img src="https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=" class="w3-round w3-image w3-opacity w3-hover-opacity-off" alt="Photo of Me" width="500" height="333"></div><!-- Hide this text on small devices --><div class="w3-col m6 w3-hide-small w3-padding-large"><p>Welcome to my website. I am lorem ipsum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute iruredolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod temporincididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p></div></div><p class="w3-large w3-center w3-padding-16">Im really good at:</p><p class="w3-wide"><i class="fa fa-camera"></i>Photography</p><div class="w3-light-grey"><div class="w3-container w3-padding-small w3-dark-grey w3-center" style="width:90%">90%</div></div><p class="w3-wide"><i class="fa fa-laptop"></i>Web Design</p><div class="w3-light-grey"><div class="w3-container w3-padding-small w3-dark-grey w3-center" style="width:85%">85%</div></div><p class="w3-wide"><i class="fa fa-photo"></i>Photoshop</p><div class="w3-light-grey"><div class="w3-container w3-padding-small w3-dark-grey w3-center" style="width:75%">75%</div></div></div><div class="w3-row w3-center w3-dark-grey w3-padding-16"><div class="w3-quarter w3-section"><span class="w3-xlarge">14+</span><br>Partners</div><div class="w3-quarter w3-section"><span class="w3-xlarge">55+</span><br>Projects Done</div><div class="w3-quarter w3-section"><span class="w3-xlarge">89+</span><br>Happy Clients</div><div class="w3-quarter w3-section"><span class="w3-xlarge">150+</span><br>Meetings</div></div><!-- Second Parallax Image with Portfolio Text --><div class="bgimg-2 w3-display-container w3-opacity-min"><div class="w3-display-middle"><span class="w3-xxlarge w3-text-white w3-wide">PORTFOLIO</span></div></div><!-- Container (Portfolio Section) --><div class="w3-content w3-container w3-padding-64" id="portfolio"><h3 class="w3-center">MY WORK</h3><p class="w3-center"><em>Here are some of my latest lorem work ipsum tipsum.<br> Click on the images to make them bigger</em></p><br><!-- Responsive Grid. Four columns on tablets, laptops and desktops. Will stack on mobile devices/small screens (100% width) --><div class="w3-row-padding w3-center"><div class="w3-col m3"><img src="https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=" style="width:100%" onclick="onClick(this)" class="w3-hover-opacity" alt="The mist over the mountains"></div><div class="w3-col m3"><img src="https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=" style="width:100%" onclick="onClick(this)" class="w3-hover-opacity" alt="Coffee beans"></div><div class="w3-col m3"><img src="https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=" style="width:100%" onclick="onClick(this)" class="w3-hover-opacity" alt="Bear closeup"></div><div class="w3-col m3"><img src="https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=" style="width:100%" onclick="onClick(this)" class="w3-hover-opacity" alt="Quiet ocean"></div></div><div class="w3-row-padding w3-center w3-section"><div class="w3-col m3"><img src="https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=" style="width:100%" onclick="onClick(this)" class="w3-hover-opacity" alt="The mist"></div><div class="w3-col m3"><img src="https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=" style="width:100%" onclick="onClick(this)" class="w3-hover-opacity" alt="My beloved typewriter"></div><div class="w3-col m3"><img src="https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=" style="width:100%" onclick="onClick(this)" class="w3-hover-opacity" alt="Empty ghost train"></div><div class="w3-col m3"><img src="https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=" style="width:100%" onclick="onClick(this)" class="w3-hover-opacity" alt="Sailing"></div><button class="w3-button w3-padding-large w3-light-grey" style="margin-top:64px">LOAD MORE</button></div></div><!-- Modal for full size images on click--><div id="modal01" class="w3-modal w3-black" onclick="this.style.display='none'"><span class="w3-button w3-large w3-black w3-display-topright" title="Close Modal Image"><i class="fa fa-remove"></i></span><div class="w3-modal-content w3-animate-zoom w3-center w3-transparent w3-padding-64"><img id="img01" class="w3-image"><p id="caption" class="w3-opacity w3-large"></p></div></div><!-- Third Parallax Image with Portfolio Text --><div class="bgimg-3 w3-display-container w3-opacity-min"><div class="w3-display-middle"><span class="w3-xxlarge w3-text-white w3-wide">CONTACT</span></div></div><!-- Container (Contact Section) --><div class="w3-content w3-container w3-padding-64" id="contact"><h3 class="w3-center">WHERE I WORK</h3><p class="w3-center"><em>I'd love your feedback!</em></p><div class="w3-row w3-padding-32 w3-section"><div class="w3-col m4 w3-container"><img src="https://media.istockphoto.com/photos/smiling-indian-business-man-working-on-laptop-at-home-office-young-picture-id1307615661?b=1&k=20&m=1307615661&s=170667a&w=0&h=Zp9_27RVS_UdlIm2k8sa8PuutX9K3HTs8xdK0UfKmYk=" class="w3-image w3-round" style="width:100%"></div><div class="w3-col m8 w3-panel"><div class="w3-large w3-margin-bottom"><i class="fa fa-map-marker fa-fw w3-hover-text-black w3-xlarge w3-margin-right"></i> Chicago, US<br><i class="fa fa-phone fa-fw w3-hover-text-black w3-xlarge w3-margin-right"></i> Phone: +00 151515<br><i class="fa fa-envelope fa-fw w3-hover-text-black w3-xlarge w3-margin-right"></i> Email: mail@mail.com<br></div><p>Swing by for a cup of <i class="fa fa-coffee"></i>, or leave me a note:</p><form action="/action_page.php" target="_blank"><div class="w3-row-padding" style="margin:0 -16px 8px -16px"><div class="w3-half"><input class="w3-input w3-border" type="text" placeholder="Name" required name="Name"></div><div class="w3-half"><input class="w3-input w3-border" type="text" placeholder="Email" required name="Email"></div></div><input class="w3-input w3-border" type="text" placeholder="Message" required name="Message"><button class="w3-button w3-black w3-right w3-section" type="submit"><i class="fa fa-paper-plane"></i> SEND MESSAGE</button></form></div></div></div><!-- Footer --><footer class="w3-center w3-black w3-padding-64 w3-opacity w3-hover-opacity-off"><a href="#home" class="w3-button w3-light-grey"><i class="fa fa-arrow-up w3-margin-right"></i>To the top</a><div class="w3-xlarge w3-section"><i class="fa fa-facebook-official w3-hover-opacity"></i><i class="fa fa-instagram w3-hover-opacity"></i><i class="fa fa-snapchat w3-hover-opacity"></i><i class="fa fa-pinterest-p w3-hover-opacity"></i><i class="fa fa-twitter w3-hover-opacity"></i><i class="fa fa-linkedin w3-hover-opacity"></i></div><p>Powered by <a href="https://www.w3schools.com/w3css/default.asp" title="W3.CSS" target="_blank" class="w3-hover-text-green">w3.css</a></p></footer><script>// Modal Image Galleryfunction onClick(element) {document.getElementById("img01").src = element.src;document.getElementById("modal01").style.display = "block";var captionText = document.getElementById("caption");captionText.innerHTML = element.alt;}// Change style of navbar on scrollwindow.onscroll = function() {myFunction()};function myFunction() {var navbar = document.getElementById("myNavbar");if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {navbar.className = "w3-bar" + " w3-card" + " w3-animate-top" + " w3-white";} else {navbar.className = navbar.className.replace(" w3-card w3-animate-top w3-white", "");}}// Used to toggle the menu on small screens when clicking on the menu buttonfunction toggleFunction() {var x = document.getElementById("navDemo");if (x.className.indexOf("w3-show") == -1) {x.className += " w3-show";} else {x.className = x.className.replace(" w3-show", "");}}</script></body></html>`);});app.listen(80);

Step 3: Let’s create the dependency files

Before proceeding with the containerization let’s crate our package.json file on the same folder with below code.

{"name": "docker-complete","version": "1.0.0","description": "","main": "server.js","license": "MIT","dependencies": {"express": "^4.17.1","body-parser": "1.19.0"}}

Step 4: Let’s create the dockerfile

Now that we are ready with our node js server and HTML/CSS template let’s create a file with the exact name Dockerfile in the same folder with below code.

FROM node
WORKDIR /app
COPY . /app/
RUN npm install
EXPOSE 80
CMD ["node", "server.js"]

These few lines of code are enough to build your image. The first lines defines the base image of your container is node and 2nd line tells you the working directory i.e. the commands should be executing from /app/ inside container. COPY command copies every other files inside /app/ then RUN command get’s exevcuted. EXPOSE commands tells which port to run in while the CMD command gets executed when the container gets launch.

Step 5: Run your container

Once you are done with everything excute the below commands from the command prompt from the same location.

$ sudo docker build .

This should be successfull and show you the container id in the output console like below.

Successful image id

If you find any issue audit your code with my github repo . Once done, finally it is time to run and map the port with host to conytainer. Run the below command.

$ sudo docker run -p 80:80 conatiner_id

This would show you nothing in console but open your browser and hit localhost:80 and voild you can find the portfolio running. What is next ?

This is the basic fun project for understanding the essence of containerization. Try to make the portfolio more realistic, find the best parctice, ctretae the following the best practices and then push the image to dockerhub registry. Comment if you have other ideas and share screenshot of what you have made. Thank you have a good day.

--

--