This is a simple Node.js web application built with HTML, CSS, JavaScript, Document Object Model and Express, intended to demonstrate Docker containerization.
- Introduction
- Requirements
- Docker Installation
- Build Docker Image
- Run Docker Container
- Stop Docker Container
- Steps To Run The Program
- Contributing
docker-practice is a basic Node.js web application that showcases how to containerize a Node.js application using Docker. It provides a simple API built with Express, and the Dockerfile is included to help you understand the steps required to create a Docker image for the application.
Before running this Docker demo, ensure you have the following software installed:
- Docker (Docker Desktop for Windows or macOS, or Docker Engine for Linux)
Please refer to the official Docker documentation to install Docker on your operating system:
- Docker Desktop for Windows (For Windows users)
- Docker Desktop for macOS (For macOS users)
- Docker Engine for Linux (For Linux users)
git clone https://github.com/Xolani-M/docker-practice.git
cd docker-practice
docker build -t username/your-app:2.0 .
# NOTE:
Replace username/your-app:2.0 with the desired name and tag for your Docker image.
docker run -p 3000:3000 username/your-app:2.0
Access the application in your web browser at http://localhost:3000.
#NOTE: When you run a Docker container with the docker run command, it starts the container in the foreground, and the terminal remains attached to the container process. In this case, you will not be able to execute docker stop directly from the same terminal where the container is running because the terminal is still busy with the container's process. Altinatively you can run the image on DETACHED mode, read further for more info.
docker run -d -p 3000:3000 xomvana022/docker-practice:2.0
- On detached mode the container runs in the background, and the terminal is free to execute other commands.
- The docker run command returns immediately with the container ID.
- You can still view the container's logs using the
docker logs <CONTAINER_ID_or_NAME>
command. - You can stop the container with
docker stop <CONTAINER_ID_or_NAME>
from the same terminal or any other terminal.
docker ps
which will list the running images in this format
CONTAINER ID | IMAGE | COMMAND | CREATED | STATUS | PORTS | NAMES |
---|---|---|---|---|---|---|
4e3gg4455235 | username/app:2.0 | "docker-entrypoint.sā¦" | About a minute ago | Up 59 seconds | 0.0.0.0:3000->3000/tcp | wizardly_almeida |
then from there, you want to select the ID or name
- Using IMAGE ID
docker stop 4e3gg4455235
- Using NAMES
docker stop wizardly_almeida
-
docker pull xomvana022/docker-practice:2.0
-
docker run -p 3000:3000 xomvana022/docker-practice:2.0
-
Using your physical machine.
-
Or go to play-with-docker to build and run a docker image.
- Login/Sign In if you have a docker id or Sign Up if you do not have a docker id.
- click "Start".
- click "ADD NEW INSTANCE" to create a new virtual machine.
#Tip: - Maximize the terminal by clicking on it and pressing "alt" + "enter"
Contributions are welcome! If you find any issues with the Docker demo or have ideas for improvements, please feel free to open an issue or submit a pull request.