Docker Tutorial for Beginners: Installation & Basic Commands

docker tutorial for beginners

Docker is one of the most widely used tools in DevOps. It is an open-source containerization platform that helps you build, package, and run applications consistently across all environments.

Docker allows you to run the same application on development, testing, and production servers without dependency or configuration issues.

In this Docker tutorial for beginners, you will learn all the basic concepts with simple explanations and easy-to-practice examples.


In This Tutorial, You Will Learn

  • What is Docker?
  • Why Docker is widely used in DevOps
  • Difference between Docker and Virtual Machines
  • How to install Docker on Linux, Windows, and Mac

What Is Docker?

Docker is a tool that helps you package your application along with its libraries and dependencies into a single unit called a container. This container can run on any system where Docker is installed.

Docker Image

A Docker image is a read-only template or blueprint used to create containers. It is built using a file called a Dockerfile, which contains step-by-step instructions to build the image.

Docker Container

A Docker container is a lightweight, standalone, and executable unit created from a Docker image. It contains the application code, libraries, and dependencies required to run the application.

Docker Hub

Docker Hub is the default cloud registry used to store Docker images. You can store images as public or private.

Other popular container registries include:

  • Amazon ECR (Elastic Container Registry)
  • Azure ACR (Azure Container Registry)
  • Google GCR (Google Container Registry)

Docker Host

A Docker host is the system where the Docker Engine is installed and running. This can be your local machine or a server.

Docker Daemon

The Docker daemon is a background service that manages Docker images, containers, volumes, and networks.


Why Docker Is Used in DevOps

  • Consistency: Runs the same across development, testing, and production environments.
  • Faster Deployment: Containers start in seconds.
  • Efficiency: Containers are lightweight and use fewer system resources.
  • Easy Scaling: You can scale applications by running more containers.

Docker vs Virtual Machines

FeatureDocker ContainersVirtual Machines
Startup TimeSecondsMinutes
SizeVery small (MBs)Very large (GBs)
Operating SystemShares host OSHas full OS
PerformanceNear nativeSlower
Resource UsageLightweightHeavy

How to Install Docker on Ubuntu (Linux)

sudo apt update
sudo apt install docker.io -y

Start and Enable Docker

sudo systemctl start docker
sudo systemctl enable docker

Verify Installation

docker --version

Sample Output:

Docker version 24.0.2, build cb74dfc

Add Your User to the Docker Group

sudo usermod -aG docker $USER

Log out and log in again to apply the changes.


Docker Installation on Windows and Mac

For Windows and Mac, Docker provides Docker Desktop.

  1. Go to the official Docker website
  2. Download Docker Desktop
  3. Install and start Docker

Basic Docker Commands

The following table lists the most important Docker commands that every beginner should know, along with their purpose.

CommandDescription
docker --versionDisplays the installed Docker version.
docker imagesLists all Docker images available on your system.
docker psShows only the currently running containers.
docker ps -aShows all containers, including stopped ones.
docker run hello-worldRuns a test container to verify that Docker is working correctly.
docker run -it ubuntu bashStarts an interactive Ubuntu container and opens a shell inside it.
docker stop <container_id>Stops a running container using its container ID.
docker rm <container_id>Removes a stopped container from the system.
docker rmi <image_id>Deletes a Docker image from the local system.
docker infoDisplays detailed information about the Docker system and configuration.
docker pull nginxDownloads the Nginx image from Docker Hub to your local machine.
docker attach <container_id>Attaches your terminal to a running container to view its output.
docker ps -q -f "state=exited"Lists only the container IDs of containers that have exited.
docker stop $(docker ps -a -q)Stops all running and stopped containers at once.
docker rm <container_name>Removes a container using its container name.

Conclusion

Docker is a core tool in modern DevOps. By learning these basic and advanced commands, you build a strong foundation for container orchestration tools like Kubernetes and for building CI/CD pipelines.

In the next tutorial, you can learn how to write your first Dockerfile and create a real Dockerized application step by step.

Be the first to comment

Leave a Reply

Your email address will not be published.


*