Skip to content

About

A step-by-step lab containerizing a Node.js app with Docker, with Git version control

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Simple Container Lab

A step-by-step guide to containerizing a simple Node.js application with Docker, and managing the project with Git version control.

Overview

This lab walks through building a minimal Node.js app, packaging it into a Docker container, running it, and pushing the project to GitHub.

Prerequisites

  • Docker installed
  • Git installed
  • Node.js (optional — only needed if you want to run app.js outside a container)
  • A GitHub account

Project Structure

.
├── README.md
├── Dockerfile
└── app.js

Stage 1: Project Initialization

Step 1 — Set Up the Project Workspace

Create a new folder to hold the project files:

mkdir simple-container-lab
cd simple-container-lab

Step 2 — Create the Application File

Create app.js, a simple script that prints a message to the console. This confirms the app runs correctly inside the container:

touch app.js
echo 'console.log("Hello from my docker container!");' > app.js

Step 3 — Create the Dockerfile

The Dockerfile tells Docker how to build the container image — the base image to use, what to copy in, and what command to run on startup:

touch Dockerfile

Add the following to Dockerfile:

FROM node:18-alpine
COPY app.js .
CMD ["node", "app.js"]

Stage 2: Build and Test the Container

Step 4 — Build the Docker Image

Package the application into a container image:

docker build -t simple-container-lab:1.0 .

Step 5 — Run the Container

Launch a container from the image to confirm the app works as expected:

docker run --rm simple-container-lab:1.0

Expected output:

Hello from my docker container!

Stage 3: Git Setup and GitHub Deployment

Step 6 — Initialize Git

git init

Step 7 — Stage the Project Files

git add .

Step 8 — Create the First Commit

git commit -m "Initial Docker container lab"

Step 9 — Connect the Remote Repository

git remote add origin https://github.com/samueleze1/simple-container-lab.git

Step 10 — Rename the Default Branch

git branch -m main

Step 11 — Push to GitHub

git push -u origin main


About

A step-by-step lab containerizing a Node.js app with Docker, with Git version control

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages