A step-by-step guide to containerizing a simple Node.js application with Docker, and managing the project with Git version control.
This lab walks through building a minimal Node.js app, packaging it into a Docker container, running it, and pushing the project to GitHub.
- Docker installed
- Git installed
- Node.js (optional — only needed if you want to run
app.jsoutside a container) - A GitHub account
.
├── README.md
├── Dockerfile
└── app.js
Create a new folder to hold the project files:
mkdir simple-container-lab
cd simple-container-labCreate 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.jsThe 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 DockerfileAdd the following to Dockerfile:
FROM node:18-alpine
COPY app.js .
CMD ["node", "app.js"]Package the application into a container image:
docker build -t simple-container-lab:1.0 .Launch a container from the image to confirm the app works as expected:
docker run --rm simple-container-lab:1.0Expected output:
Hello from my docker container!
git initgit add .git commit -m "Initial Docker container lab"git remote add origin https://github.com/samueleze1/simple-container-lab.gitgit branch -m maingit push -u origin main