What is Docker?
Docker is a tool that packages software into standardized units called containers. Think of a container as a lightweight, portable box that contains everything your application needs to run: the code, runtime, libraries, and settings.
The Problem Docker Solves
Have you ever experienced:
- "It works on my machine, but not on the server"
- Hours spent installing dependencies before you can run software
- Conflicts between different versions of libraries
- Difficulty replicating someone else's development environment
Docker solves these problems by packaging everything together so the software runs identically everywhere.
A Simple Analogy
Think of Docker like shipping containers used in global trade:
- Before containers: Cargo was loaded loose onto ships. Each ship was loaded differently. Moving cargo between ships, trains, and trucks required repacking.
- After containers: All cargo fits in standard-sized boxes. Any ship, train, or truck can carry them. No repacking needed.
Similarly, Docker containers package software in a standard format that runs anywhere Docker is installed.
Key Concepts
Image
An image is a read-only template. It's like a recipe or blueprint. Images are created once and can be shared. Examples:
alpine:latest- A minimal Linux distribution (5 MB)nginx:alpine- A web serverpostgres:16-alpine- A database server
Container
A container is a running instance of an image. Like a class and an object in OOP:
- Image = Class (the definition)
- Container = Object (a running instance)
You can run many containers from the same image.
Registry
A registry stores images. Docker Hub is the public registry with thousands of free images. When you "pull" an image, you download it from a registry.
Why Use Docker from Eiffel?
With simple_docker, your Eiffel applications can:
1. Run Databases Without Installation
Need PostgreSQL? Instead of installing it on your system:
create spec.make ("postgres:16-alpine")
spec.add_env ("POSTGRES_PASSWORD", "secret")
.add_port (5432, 5432)
.do_nothing
container := client.run_container (spec)
Your database is running in seconds. No installer, no configuration files.
2. Run Isolated Tests
Each test gets its own fresh environment:
-- Start fresh database for each test
container := client.run_container (spec)
-- Run your tests
run_database_tests
-- Clean up completely
client.remove_container (container.id, True)
3. Deploy Consistent Environments
Package your Eiffel application with all its dependencies:
create builder.make ("alpine:latest")
builder.copy_files ("my_app.exe", "/app/")
.cmd (<<"/app/my_app.exe">>)
.do_nothing
4. Run Third-Party Services
Redis, RabbitMQ, Elasticsearch - run any service without learning its installation:
-- Need a cache server?
create spec.make ("redis:alpine")
spec.add_port (6379, 6379).do_nothing
client.run_container (spec)
Minimal Complete Example
This example runs a container, captures its output, and cleans up:
class
DOCKER_HELLO_WORLD
create
make
feature {NONE}
make
local
client: DOCKER_CLIENT
spec: CONTAINER_SPEC
container: detachable DOCKER_CONTAINER
do
-- Connect to Docker
create client.make
if client.ping then
print ("Docker is running!%N")
-- Create a simple container that prints a message
create spec.make ("alpine:latest")
spec.set_cmd (<<"echo", "Hello from Docker!">>).do_nothing
-- Run it
container := client.run_container (spec)
if attached container as c then
-- Wait for it to finish
client.wait_container (c.id).do_nothing
-- Get the output
if attached client.container_logs (c.id, True, False, 100) as logs then
print ("Container output: " + logs + "%N")
end
-- Clean up
client.remove_container (c.id, True).do_nothing
print ("Container removed%N")
end
else
print ("Docker is not running. Please start Docker Desktop.%N")
end
end
end
Next Steps
- Install Docker Desktop (free for personal use)
- Start Docker Desktop and wait for it to say "Docker is running"
- Read the User Guide for installation
- Try the Cookbook recipes for real-world examples
FAQ
Is Docker a virtual machine?
No. Virtual machines emulate complete computers with their own operating system. Containers share the host's operating system kernel, making them much lighter and faster to start (seconds vs. minutes).
Do I need Linux to use Docker?
No. Docker Desktop runs on Windows and macOS. It handles Linux containers seamlessly through a lightweight VM. simple_docker connects via Windows named pipes.
Is it safe?
Containers are isolated from your system. They can only access what you explicitly allow (ports, files, etc.). Always use official images from trusted sources.
What if I don't have internet?
Images only need to be downloaded once. After that, they're cached locally. You can also export/import images for offline use.