Practical Example — Docker in Action
Before we start learning Docker commands, let's look at a very practical example that will give us complete clarity on what Docker exactly is.
We have a host machine — let's say a Mac OS system. On this Mac OS, suppose we want to run an Ubuntu system. The command to do this (which we will cover in detail later) looks like:
This command runs an Ubuntu container inside Docker in interactive mode, allowing us to access the terminal of that container.
As soon as this command is executed, Docker:
- Checks whether the required image is available locally.
- If available, uses the local image.
- If not available, downloads it from Docker Hub.
- Creates and starts a container from that image.
We can verify this using Docker Desktop. In the Containers tab, we can see:
- The running container
- The image it was created from
- Its current status
- Its unique container ID
Inside the container, we are placed in the root directory. The files and folders visible there belong only to the Ubuntu container.
For example:
- Creating a new directory affects only the container.
- Creating or deleting files affects only the container.
- None of these changes impact the Mac OS host machine.
Even if we delete the entire container tomorrow, our Mac OS remains completely unaffected.
What Happened?
In this example, we:
- Downloaded the Ubuntu image from the internet.
- Created a container from the image.
- Worked inside that container independently.
This is the core idea of Docker.
Docker is similar to a Virtual Machine (VM), but it is much more lightweight, faster, and easier to work with.
Setting Up Docker on Your Local System
To set up Docker, visit docker.com and download Docker Desktop.
Docker Desktop is available for both Mac and Windows systems.
Installation on Mac
- Visit docker.com.
- Click the Download Docker Desktop button.
- Select the appropriate chip:
- Download and install Docker Desktop.
Installation on Windows
- Visit docker.com.
- Select Windows AMD64.
- Start the download.
- Run the installer.
- Docker Desktop installation will begin.
- Grant any requested administrator permissions.
- Allow Docker to make required system changes.
- Once installation is complete, click Close and Restart.
- After the restart:
- Open Docker Desktop.
- Accept the license agreement.
- Choose Recommended Settings.
- Click Finish.
- Optionally skip the login step.
- Select Full Stack Developer.
- Continue until the Docker Engine starts successfully.
Verifying Docker Installation
Open the terminal (Mac/Linux) or Command Prompt (Windows) and run:
If Docker commands are displayed, Docker has been installed successfully.
To check the Docker version:
Example output:
Docker version 28.x.x, build xxxxxxx
Docker Hub
Just as GitHub is a central repository for source code, Docker Hub is a central repository for Docker images.
Docker Hub contains thousands of public Docker images that can be downloaded and used directly.
When Docker cannot find an image locally, it automatically pulls it from Docker Hub.
Access Docker Hub
Visit:
Uses of Docker Hub
- Store Docker images
- Share images publicly
- Pull official images
- Version and manage container images
- Use community-maintained images
Examples of Popular Images
- Ubuntu
- Nginx
- MySQL
- Redis
- MongoDB
- Node.js
Docker Hub acts as the central registry from which Docker retrieves images whenever they are not available on the local machine.