What is a Container and How to Create It
Simple explanation of what containers are and how to create them in Docker.
π³ What is a Container and How to Create It
A container is a lightweight, standalone, and executable software package that includes everything an application needs to run β like code, runtime, system tools, libraries, and settings. Itβs a virtual environment created from a Docker image, allowing you to run your app consistently on any machine.
Containers are isolated from the host system, meaning each container runs its own process independently without interfering with others. This makes containers perfect for microservices, DevOps, and cloud deployment.
βοΈ How a Container Works
- A Docker image is like a blueprint (a static snapshot).
- A Docker container is a running instance of that image.
- You can have multiple containers running from the same image, each isolated and independent.
Example:
- Image = recipe
- Container = dish made from that recipe
π How to Create a Container
Before creating a container, make sure Docker is installed and the image you want to use is available.
You can either:
- Use an existing image from Docker Hub (like
nginx,ubuntu,mysql, etc.) - Or build your own image using a Dockerfile and then run it as a container.
π§© Step 1: Pull or Build an Image
To pull a ready-made image from Docker Hub:
docker pull nginxOr build your own image (example: myapp):
docker build -t myapp .π Step 2: Create and Run a Container
Once you have an image, run it using:
docker run -d -p 8080:80 --name mycontainer nginxExplanation:
docker runβ creates and starts a container.-dβ runs it in detached mode (background).-p 8080:80β maps port 8080 on your computer to port 80 in the container.--name mycontainerβ assigns a custom name to the container.nginxβ is the name of the image used to create the container.
π§± Step 3: Check Running Containers
To list all active containers:
docker psTo see all containers (including stopped ones):
docker ps -aπ§Ή Step 4: Manage Containers
You can stop, start, or remove containers anytime.
Stop a container:
docker stop mycontainerStart a stopped container:
docker start mycontainerRemove a container:
docker rm mycontainerβ In short: A container is a running environment built from an image that isolates your application and its dependencies, making it portable, efficient, and reliable across any system running Docker.
What is DevOps? β The Complete Beginner Guide
Understand what DevOps is, why it was created, and why itβs essential in modern software development.
Creating Dockerfiles for React.js, Java, and .NET Applications
Simple text notes explaining how to create Dockerfiles for React.js, Java, and .NET apps.