Docker Fundamentals
Docker Basics
What is Docker?
Every developer has heard the dreaded phrase: “But it works on my machine!” An application runs perfectly on one computer but breaks on another. This usually happens because the two environments are different. Maybe one has a different operating system version, or a crucial library is missing.
Docker solves this problem by packaging an application, along with all its dependencies like libraries and settings, into a single, standardized unit. This unit is called a container.
Container
noun
A lightweight, standalone, executable package of software that includes everything needed to run it: code, runtime, system tools, system libraries, and settings.
Think of containers like shipping containers. It doesn't matter what's inside—electronics, bananas, or clothes—the container itself has a standard shape and size. This allows it to be moved and stacked by any crane, ship, or truck.
Similarly, a Docker container can run on any computer that has Docker installed, regardless of the underlying operating system. This creates consistency from development to testing to production.
Docker's main goal is to ensure that an application runs the same way everywhere.
Docker's Architecture
Docker uses a client-server architecture. You use the Docker client to send commands to the Docker server, which does all the work. Let's look at the main parts.
Docker Engine: This is the server part, also known as the Docker daemon. It's a background process that manages Docker objects like images, containers, networks, and volumes. It listens for commands from the Docker client and does the heavy lifting.
Docker CLI: The Command-Line Interface (CLI) is the client you interact with. When you type a command like docker run, the CLI sends it to the Docker daemon, which then executes it.
Docker Hub: A registry is a place where Docker images are stored. Docker Hub is the default public registry that Docker uses. It's like a GitHub for Docker images, where you can find thousands of pre-built images for common software or upload your own.
Getting Docker Set Up
Docker is available for Windows, macOS, and various distributions of Linux. The easiest way to get started on a desktop is with Docker Desktop.
Docker Desktop is an application for Mac and Windows that provides an easy-to-use development environment. It includes the Docker Engine, the Docker CLI client, and other helpful tools. For Linux, you'll install the Docker Engine and client directly.
The process is straightforward: visit the official Docker website, download the appropriate installer for your operating system, and follow the installation wizard. You may need to create a free Docker account to download it.
Checking Your Installation
Once the installation is complete, you should verify that Docker is running correctly. Open your terminal or command prompt and run a simple command. This command downloads a small test image from Docker Hub, runs a container from it, prints a message, and then exits.
docker run hello-world
If everything is set up properly, you will see a message that begins with:
Hello from Docker! This message shows that your installation appears to be working correctly.
This confirms that your client was able to talk to the daemon, which then pulled an image and ran a container. You're now ready to start using Docker.
