Git Product home page Git Product logo

muhammad-faisal-kemal_weekly_w6's Introduction

Week 6 Assignment - Dockerize Nodejs Hello World App

OS: Windows 11 Version 22H2

Docker Desktop: 4.21.1.114176

NodeJS Docker Image: Version 18.17.0(LTS)

Install Docker and Update WSL

  1. Download docker desktop from www.docker.com and run it

    6v_1.mp4
  2. Update Windows Subsystem for Linux with this command and run docker desktop again

    wsl --update
    
    6v_2.mp4
  3. Verify docker installation with this command

    docker --version
    

    6i_1

Download Nodejs Image on Docker

  • Download nodejs version 18.17.0(LTS) image on docker with this command

    docker pull node:18.17.0-alpine
    
    6v_3.mp4
  • For other version of nodejs images tag, you can check at this link https://hub.docker.com/_/node/

Download Nodejs Hello World(app.js) and Prepare Dockerfile

  1. Download app.js from https://gist.github.com/berdoezt/e51718982926f0caa3fcd8ed45111430 and move to new folder
  2. Create file with name Dockerfile, edit file with this code, and save at same folder with app.js
    #Tells docker base image to use
    #nodejs version 18.17.0-alpine(LTS version)
    FROM node:18.17.0-alpine
    
    #The environment application is production
    ENV NODE_ENV=production
    
    #Location of working directory
    WORKDIR	/app
    
    #The COPY command takes all the files located in
    #the current directory and copies them into the image
    COPY . .
    
    #Informs Docker that the container listens
    #on the port 3001
    EXPOSE	3001
    
    #Tell Docker what command to run
    CMD	["node", "app.js"]
    

Dockerize Nodejs Hello World(app.js) And Run It

  1. Open folder of the app on command prompt, after that run this command

    docker build -t nodejs_hello-world .
    
  2. Check images succesful built with this command

    docker images
    
  3. Run app with this command(binds port 3001 of container to port 3000 of host)

    docker run -p 3000:3001 nodejs_hello-world
    
  4. Finally, open browser to check app running well with this link

    localhost:3000
    
    6v_4.mp4

Review Assignment Due Date

muhammad-faisal-kemal_weekly_w6's People

Contributors

mfaisalkemal avatar github-classroom[bot] avatar

Watchers

Alvian Zachry Faturrahman avatar

Forkers

mfaisalkemal

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.