In today's software development world, the shift from monolithic to microservices architecture has revolutionized how we build and deploy applications. At the heart of this evolution is Docker a platform that enables developers to package, ship, and run applications in lightweight, portable containers.
This article provides a comprehensive overview of Docker, explains what containers are, and walks through the process of dockerizing an application with practical examples.
What Is Docker?
Docker is an open-source platform that allows developers to automate the deployment of applications inside lightweight, portable containers. These containers run consistently across any environment—whether it's a developer's laptop, a test server, or a production cloud environment.
Docker uses containerization technology to package an application with all its dependencies, configuration files, libraries, and binaries, ensuring it will run the same regardless of where it's deployed.
What Are Containers?
A container is a standard unit of software that encapsulates an application and all its dependencies so it can run quickly and reliably across different environments.
Unlike virtual machines (VMs), containers do not include a full operating system. They share the host OS kernel and isolate the application processes. This makes them more lightweight and faster to start compared to VMs.
Containers vs Virtual Machines
Here’s a quick comparison between Virtual Machines and Containers:
Feature | Virtual Machines | Containers |
---|---|---|
OS | Includes guest OS | Shares host OS kernel |
Resource Usage | Heavy (more memory & CPU) | Lightweight |
Boot Time | Minutes | Seconds |
Portability | Less portable | Highly portable |
Docker Architecture
Docker has three major components:
- Docker Client – CLI tool (docker) that users interact with.
- Docker Daemon – Runs in the background to manage containers.
- Docker Images – Read-only templates used to create containers.
- Docker Containers – Running instances of Docker images.
- Docker Registry – A repository for Docker images (e.g., Docker Hub).
Why Use Docker?
Consistency across environments
Rapid deployment and scalability
Isolation of applications
Efficient CI/CD integration
Simplified dependency management
Microservices support
Setting Up Docker
Install Docker from the official website or use your system’s package manager:
Ubuntu: sudo
apt install docker.io
macOS: Use Docker Desktop
Windows: Use Docker Desktop (WSL 2 backend recommended)
Check installation:
docker --version
Dockerizing an Application
To show you how to dockerize an application, I have dockerized a Prime Video clone built with React. The original frontend project can be found here: Prime Video Clone on GitHub. My Docker setup allows the app to run consistently across environments, making it production-ready and easily deployable.
Create a Dockerfile
A Dockerfile is a text file that contains a set of instructions Docker uses to build a Docker image. Think of it as a blueprint for packaging your application and its environment (OS, libraries, dependencies, etc.) into a portable container.
When you run docker build
, Docker reads the Dockerfile line by line, executing each instruction to assemble the final image.
Inside your project root (prime-video-clone/)
, create a Dockerfile
# Use official Node.js base image for build step
FROM node:20-alpine
# Set working directory
WORKDIR /app
# Copy package files and install dependencies
COPY package*.json .
RUN npm install
# Copy the rest of the source code
COPY . .
# Expose port 3000
EXPOSE 3000
# Start app
CMD [ "npm", "start"]
Add a .dockerignore File
Exclude unnecessary files from your Docker build context:
node_modules
build
.dockerignore
Dockerfile
.git
.gitignore
Build the Docker Image
Open your terminal and run:
docker build -t kelzceana/prime-video-appe .
Run the Container
To run the app locally on port 3000
docker run -d -p 3000:3000 kelzceana/prime-video-app
Conclusion
Dockerizing your Prime Video clone not only improves the developer experience, but also prepares your app for real-world deployment scenarios. You now have a portable, production-ready version of your React frontend all in a single container.
Top comments (0)