RIPPLE: PRABIN SAHANI
Part 1: Introduction & essential commands
Docker is an open platform for developing, shipping and running applications. In today’s development world, applications are no longer simple scripts that run on a single machine. They often depend on multiple libraries, services, and configurations, which can vary from one environment to another. This leads to the classic problem:
“It works on my machine, but not in production.”
Docker solves this. Docker is a platform that lets you package your application along with everything it needs—libraries, runtime, configuration—into a lightweight, portable container. These containers run the same way everywhere: on your laptop, staging server, or production environment.
Why use Docker?
- Consistency: Docker eliminates environment mismatch issues. You can run your application the same way in any environment, from development to production.
- Isolation: Docker runs multiple apps without conflicts. Containers are isolated from each other and the host system, improving security and reducing conflicts.
- Portability: Docker containers work on any system that runs Docker regardless of the underlying infrastructure.
- Speed: Docker starts containers in seconds (faster than virtual machines).
- Scaling: Docker containers can be easily and quickly scaled up or down.
- Versioning: You can version and roll back containers like code.
Docker Key Concepts:
- Images: Images are one of the two core building blocks in Docker. Images are blueprints / templates for containers. They are read-only and contain the application as well as the necessary application environment (operating system, runtimes tools, etc). Images do not run themselves, instead, they can be executed as containers. Images are either pre-built(e.g. official images on DockerHub) or you build your own images by defining a Dockerfile. Dockerfiles contain instructions which are executed when an image is built, every instruction then creates a layer in the image. Layers are used to efficiently rebuild and share images.
Sample DockerFile:
# FROM specifies the base image to use
FROM ubuntu:20.04
# RUN executes commands in a new layer on top of the current image
RUN apt-get update && apt-get install -y nginx
# COPY copies files from the host into the image
COPY ./my-nginx.conf /etc/nginx/nginx.conf
# EXPOSE informs Docker that the container listens on specified network ports at runtime.
EXPOSE 80
# CMD provides defaults for an executing container
CMD [“nginx”, “-g”, “daemon off;”]
- Containers: Containers are another key building block in Docker. Containers are running instances of Images. When you create a container, a thin read-write layer is added on top of the Image. Multiple Containers can therefore be started based on one and the same Image. All containers run in isolation, i.e. they don’t share any application state or written data. You need to create and start a Container to start the application which is inside of a Container. So it’s Containers which are in the end executed – both in development and production.
- Registry: An image registry is a centralized location for storing and sharing your container images. Images can be private or public. Docker Hub is a public registry that anyone can use and is the default registry. While Docker Hub is a popular option, there are many other available container registries available today, including Amazon Elastic Container Registry(ECR), Azure Container Registry (ACR), and Google Container Registry (GCR).
- Docker Compose: Docker Compose is a tool that helps you define and run multi-container Docker applications using a simple configuration file — typically called docker-compose.yml. Instead of running each container manually with docker run, Compose lets you define all services, networks, and volumes in one place, and then start them all at once with a single command.
Key Docker Commands
For a full list of all commands, add –help after a command – e.g. docker –help, docker run –help etc.
- docker build .: Build a Dockerfile and create your own Image based on the file.
- -t NAME:TAG: Assign a NAME and a TAG to an image
- docker run IMAGE_NAME: Create and start a new container based on image IMAGE_NAME (or use image id)
- –name NAME: Assign a NAME to the container.
- -d: Run container in detached mode.
- -it: Run container in interactive mode.
- –rm: Automatically remove the container when it’s stopped.
- -p: Run container in port (format 3000:2222)
- docker ps: List all running containers.
- -a: List all containers including stopped ones.
- docker images: List all locally stored images.
- docker rm CONTAINER: Remove a container with name / id CONTAINER.
- docker rmi IMAGE: Remove an image by name / id.
- docker container prune: Remove all stopped containers.
- docker image prune: Remove all dangling images(untagged images).
- -a: Remove all locally stored images.
- docker push IMAGE: Push an image to DockerHub (or another registry).
- docker pull IMAGE: Pull an image from DockerHub (or another registry).
Conclusion
In this first part of the series, we introduced Docker, explored why it’s used, and got familiar with its core concepts like images, containers, and Dockerfiles. We also covered some of the most commonly used Docker commands to help you get started with containerization. In the next part of the series, we’ll dive into Docker Volumes—how they work, why they matter, and how to use them to persist and manage data across containers. Stay tuned!
