KAHIBARO Bookshelves
Discord Login Register

1.2. Why Docker?

The Problem Docker Tries to Solve

Before Docker, developers and operations teams often fought with a simple but painful issue. Code worked on one machine but failed on another. Different operating systems, library versions, system settings, and manual setup steps made environments fragile and hard to reproduce.

Applications grew more complex, with multiple services, databases, queues, and external dependencies. Setting up and keeping all of this consistent across laptops, test servers, and production environments became slow and error prone.

Docker exists to solve this environment problem by giving you a reliable way to package an application together with everything it needs to run, so it behaves the same, no matter where it is started.

Consistency Across Environments

With Docker, you describe your application environment in a clear, repeatable form. The result is a container image that already includes the runtime, libraries, and configuration the application expects.

This has a direct benefit. The image you test locally is the same image you deploy on a server. Instead of someone writing a long setup guide and hoping everyone follows it correctly, the environment definition travels with your code.

Key idea: A Docker image that works on one Docker host will behave the same way on any other compatible Docker host.

This consistency greatly reduces the “works on my machine” problem, because the machine details matter less than the container environment.

Isolation Without Heavy Virtual Machines

Traditional virtual machines create a full guest operating system on top of a hypervisor. Each VM includes its own OS kernel and system services. This gives strong isolation, but also uses a lot of memory and CPU, and can be slow to start.

Containers, which Docker manages, isolate applications at the process level instead of running a separate operating system for each one. Multiple containers share the same host kernel while still having separate filesystems, processes, and networking.

Because of this, containers typically start faster and use fewer resources than virtual machines. You can run more isolated workloads on the same hardware, which is attractive for both development machines and servers.

Faster Developer Feedback

Docker shortens the time between writing code, running it, and getting feedback. Once you have a container image defined, spinning up an instance of your application becomes a single command. You do not need to repeatedly install dependencies manually.

Developers can run multiple versions of the same dependency on one machine inside separate containers. For example, testing an application with two different database versions, without uninstalling or reinstalling anything on the host, becomes straightforward.

This faster loop encourages experimentation, more frequent testing, and more reliable validation of behavior before any code is merged or deployed.

Easier Onboarding and Collaboration

New developers usually need to set up many tools before they can contribute to a project. This can take hours or days and often leads to subtle differences between team members’ setups.

With Docker, setup can be simplified to installing Docker itself and then using predefined container configurations. When a project includes a Docker based environment description, a new team member can often start by running a few commands to get a working stack.

The shared container configuration also becomes a common reference point for the whole team. Instead of “follow this wiki page,” teams can point to the Docker files that define the real environment.

Reproducible Builds and Deployments

In many projects, the build process for an application and the deployment process to servers involve many small steps that can drift over time. Docker encourages you to encode those steps in a way that is repeatable.

You build a container image once and then deploy that same image across different environments. This reduces the risk that a deployment script or manual step behaves differently between environments.

Important property: Build once, run anywhere that supports Docker, using the same immutable image.

This immutability simplifies debugging. When something goes wrong in production, you can pull the exact same image, start it in a controlled environment, and inspect it without guessing how it was configured.

Portability Across Platforms and Infrastructure

Docker abstracts away many details of the underlying infrastructure. As long as the host can run Docker and supports the container’s base architecture, the same image can be started on different cloud providers, on premises servers, or developer laptops.

This portability is valuable when teams want to avoid strong coupling to a single provider, or when they need to move workloads between test and production environments that are not identical at the operating system level.

Container registries act as a neutral distribution point. Once an image is stored there, any compatible environment with network access can download and run it.

Resource Efficiency and Density

Because containers share the host operating system kernel instead of running full guest operating systems, they tend to be lighter than virtual machines. Memory and disk overhead are lower, and container images can reuse common layers efficiently.

On a given server, you can usually run more containerized workloads than VM based ones with the same hardware capacity. This is attractive for reducing infrastructure cost or making better use of existing machines.

Resource efficiency also matters for local development. Developers often run databases, caches, message brokers, and application services on a single laptop. Containers make this more feasible by reducing the footprint of each component.

Alignment with Modern Architectures

Many modern applications are built as collections of smaller, independent services. Docker fits naturally into this style, because each service can run in its own container with its own dependencies and configuration.

Even for a single application, separating supporting systems into containers can help. Instead of installing a database directly on your machine, you can run a database container alongside your application container, each with clear boundaries.

This modular style aligns well with orchestration tools that manage many containers across clusters of machines, which become relevant as systems grow.

Improved Testing Practices

Testing benefits from environments that are predictable, disposable, and easy to set up. Docker provides all three. You can create fresh containers for integration tests and destroy them when the tests finish.

Because the environment is described in code, tests can rely on having the right versions of services, databases, and other dependencies, instead of depending on what happens to be installed on a shared test server.

It also becomes easier to reproduce complex scenarios, such as testing how an application behaves with certain configuration combinations or under specific service topologies, by starting containers in controlled ways.

Support from Tools and Ecosystem

Over time, a large ecosystem has formed around Docker. Many programming languages, frameworks, and platforms provide official container images and documentation. Build systems, continuous integration tools, and deployment platforms often include first class Docker support.

This broad support reduces the amount of custom work required to integrate Docker into existing workflows. Teams can adopt Docker step by step, starting with development, or testing, or packaging, while relying on familiar tools that already understand how to work with containers.

For beginners, this means that examples, tutorials, and community resources are widely available, which lowers the barrier to getting real value from Docker early in the learning process.

Views: 0

Comments

Please login to add a comment.

Don't have an account? Register now!

Where to Move

Move chapter:

  • ☰ 1. Introduction
    • ☰ 1.1. What is Docker?
      • ☰ 1.2. Why Docker?
        • ☰ 1.3. Virtual Machines vs Containers
          • ☰ 1.4. When Not to Use Docker
            • ☰ 1.5. How Docker Is Used in Real Projects
            • ☰ 2. Core Concepts
              • ☰ 2.1. Images
                • ☰ 2.2. Containers
                  • ☰ 2.3. Docker Engine and Architecture
                    • ☰ 2.4. Docker Hub and Container Registries
                      • ☰ 2.5. Tags, Versions, and Digests
                      • ☰ 3. Installing Docker
                        • ☰ 3.1. Docker on Linux
                          • ☰ 3.2. Docker on Windows
                            • ☰ 3.3. Docker on macOS
                              • ☰ 3.4. Verifying the Installation
                                • ☰ 3.5. Common Installation Issues
                                • ☰ 4. Your First Docker Container
                                  • ☰ 4.1. Running Your First Container
                                    • ☰ 4.2. Understanding `docker run`
                                      • ☰ 4.3. Interactive vs Detached Mode
                                        • ☰ 4.4. Stopping and Removing Containers
                                          • ☰ 4.5. Listing Containers
                                          • ☰ 5. Working with Docker Images
                                            • ☰ 5.1. Pulling Images from Docker Hub
                                              • ☰ 5.2. Listing and Removing Images
                                                • ☰ 5.3. Image Layers Explained
                                                  • ☰ 5.4. Image Size Optimization
                                                    • ☰ 5.5. Inspecting Images
                                                    • ☰ 6. Dockerfiles – Building Your Own Images
                                                      • ☰ 6.1. What Is a Dockerfile?
                                                        • ☰ 6.2. Basic Dockerfile Structure
                                                          • ☰ 6.3. Common Instructions (`FROM`, `RUN`, `COPY`, `CMD`, `ENTRYPOINT`)
                                                            • ☰ 6.4. Building Images with `docker build`
                                                              • ☰ 6.5. Best Practices for Dockerfiles
                                                                • ☰ 6.6. Multi-Stage Builds
                                                                • ☰ 7. Managing Data with Volumes
                                                                  • ☰ 7.1. Why Containers Are Ephemeral
                                                                    • ☰ 7.2. Bind Mounts vs Volumes
                                                                      • ☰ 7.3. Creating and Using Volumes
                                                                        • ☰ 7.4. Inspecting and Removing Volumes
                                                                          • ☰ 7.5. Real-World Examples
                                                                          • ☰ 8. Networking in Docker
                                                                            • ☰ 8.1. Docker Networking Basics
                                                                              • ☰ 8.2. Bridge Networks
                                                                                • ☰ 8.3. Port Mapping
                                                                                  • ☰ 8.4. Container-to-Container Communication
                                                                                    • ☰ 8.5. Custom Networks
                                                                                    • ☰ 9. Docker Compose
                                                                                      • ☰ 9.1. Why Docker Compose?
                                                                                        • ☰ 9.2. `docker-compose.yml` Structure
                                                                                          • ☰ 9.3. Defining Services, Networks, and Volumes
                                                                                            • ☰ 9.4. Running Multi-Container Applications
                                                                                              • ☰ 9.5. Web App and Database Example
                                                                                                • ☰ 9.6. Docker Compose Best Practices
                                                                                                • ☰ 10. Debugging and Monitoring Containers
                                                                                                  • ☰ 10.1. Viewing Logs
                                                                                                    • ☰ 10.2. Executing Commands in Running Containers
                                                                                                      • ☰ 10.3. Inspecting Containers
                                                                                                        • ☰ 10.4. Resource Usage
                                                                                                          • ☰ 10.5. Common Errors and Fixes
                                                                                                          • ☰ 11. Security Basics
                                                                                                            • ☰ 11.1. Running Containers as Non-Root
                                                                                                              • ☰ 11.2. Image Trust and Verification
                                                                                                                • ☰ 11.3. Secrets and Environment Variables
                                                                                                                  • ☰ 11.4. Reducing Attack Surface
                                                                                                                    • ☰ 11.5. Security Best Practices
                                                                                                                    • ☰ 12. Performance and Optimization
                                                                                                                      • ☰ 12.1. Reducing Image Size
                                                                                                                        • ☰ 12.2. Caching and Layer Ordering
                                                                                                                          • ☰ 12.3. Resource Limits
                                                                                                                            • ☰ 12.4. Choosing the Right Base Image
                                                                                                                            • ☰ 13. Docker in Development Workflows
                                                                                                                              • ☰ 13.1. Docker for Local Development
                                                                                                                                • ☰ 13.2. Hot Reloading with Volumes
                                                                                                                                  • ☰ 13.3. Docker and Git
                                                                                                                                    • ☰ 13.4. Docker in CI/CD Pipelines
                                                                                                                                      • ☰ 13.5. Common Development Patterns
                                                                                                                                      • ☰ 14. Deployment Basics
                                                                                                                                        • ☰ 14.1. Running Containers in Production
                                                                                                                                          • ☰ 14.2. Environment Configuration
                                                                                                                                            • ☰ 14.3. Restart Policies
                                                                                                                                              • ☰ 14.4. Logging Strategies
                                                                                                                                                • ☰ 14.5. Basic Scaling Concepts
                                                                                                                                                • ☰ 15. Beyond the Basics
                                                                                                                                                  • ☰ 15.1. Docker Swarm Overview
                                                                                                                                                    • ☰ 15.2. Kubernetes vs Docker
                                                                                                                                                      • ☰ 15.3. Container Registries
                                                                                                                                                        • ☰ 15.4. When to Move Beyond Docker
                                                                                                                                                        • ☰ 16. Practical Projects
                                                                                                                                                          • ☰ 16.1. Dockerizing a Simple Web App
                                                                                                                                                            • ☰ 16.2. Dockerizing a Backend API
                                                                                                                                                              • ☰ 16.3. Full-Stack App with Docker Compose
                                                                                                                                                                • ☰ 16.4. Common Project Pitfalls
                                                                                                                                                                • ☰ 17. Troubleshooting and FAQ
                                                                                                                                                                  • ☰ 17.1. Common Beginner Mistakes
                                                                                                                                                                    • ☰ 17.2. Docker Command Cheat Sheet
                                                                                                                                                                      • ☰ 17.3. FAQ
                                                                                                                                                                        • ☰ 17.4. Useful Resources