What is a Container ? (original) (raw)

Last Updated : 23 Aug, 2025

A container is an isolated, stand-alone unit that encapsulates an application and all its dependencies. It runs consistently in any environment, independent of the host system.

environments

It is a light, executable software package that wraps everything an application needs libraries, configuration files, and binaries. This ensures the application behaves the same way whether on a developer’s laptop, testing environment, or production server. Unlike traditional virtual machines that carry a full OS, containers only pack what is required, making them faster and more efficient.

Containers vs. Virtual Machines (VMs)

Both containers and VMs allow running applications in isolated environments, but they differ in architecture, performance, resource usage, and startup time.

containers

Containers

Virtual Machines (VMs)

What is Containerization?

Containerization is the process of packing an application together with all its dependencies into a container in order to allow the application to run consistently from one computing environment to another, in simple terms containerization involves using the host OS kernel to run many isolated instances of applications on the same machine, making it very lightweight and efficient in deploying applications.

Use Cases for Containerization

Step-by-Step Process: How Containers Work?

These steps to understand how containers are created, built into images, and run to deliver applications consistently across environments.

Step 1: Install Docker

sudo yum -y install docker

Install Docker

sudo systemctl start docker sudo systemctl enable docker sudo systemctl status docker

To Start,Enable & Check Status Of Docker

Step 2: **Create a Dockerfile

Example Dockerfile:

# Use an official Node.js runtime as the base image.

FROM node:14

# Specify the working directory inside the container.

WORKDIR /app

# Copy package.json and package-lock.json files

COPY package*.json ./

# Install the application dependencies

RUN npm install

# Copy the rest of the application code

COPY . .

# Define the command to run the application

CMD ["node", "app.js"]

Dockerfile

Step 3: Create package.json file

{

"name": "my-node-app",

"version": "1.0.0",

"main": "app.js",

"dependencies": {

"express": "^4.17.1"

}

}

package.json file

Step 4: **Create the app.js File

const express = require('express');

const app = express();

const port = 3000;

app.get('/', (req, res) => {

res.send('Hello, World!');

});

app.listen(port, () => {

console.log(`App running on http://localhost:${port}\`);

});

Create the app.js File

Step 5: **Build the Container Image

Use the Dockerfile to build the container image. This image includes the application code, all dependencies, and any necessary environment settings.

Command to build the image:

docker build -t my-node-app .

Command to build the image

**Step 6: Store the Image

After building the image, it can be stored locally or pushed to a container registry (like Docker Hub or a private registry).

Command to push the image to Docker Hub:

docker push my-node-app

Command to push the my-node-app Image to Docker Hub

Step 7: **Run the Container

docker run -d -p 3000:3000 my-node-app

Run the Container

docker ps

To Check Container List

Step 8: Access the Application

Finally, if everything is set up correctly, you should be able to access your Node.js application by navigating to http://<Public IP >:3000 in your web browser.

Access the Application

Benefits of Containers