Docker Desktop Setup
Docker lets you package your app and everything it needs into a container โ so it runs the same everywhere. This guide installs Docker Desktop and gets you running your first container.
Docker does the same for software. Your app + its OS dependencies + config = one container. It runs the same on your laptop, your colleague's Mac, and a Linux server in Azure. No more "it works on my machine!"
| Concept | Real-World Equivalent | In Docker |
|---|---|---|
| Docker Image | A recipe / blueprint | Read-only template (built from Dockerfile) |
| Docker Container | An actual meal / product | Running instance of an image |
| Dockerfile | Step-by-step cooking instructions | File that defines how to build an image |
| Docker Hub | A library of recipes | Public registry of Docker images |
| docker-compose | A catering company | Runs multiple containers together |
Container vs Virtual Machine
| Feature | Container | Virtual Machine |
|---|---|---|
| Startup time | Seconds | Minutes |
| Size | MBs | GBs |
| OS included? | No (shares host kernel) | Yes (full OS) |
| Isolation | Process-level | Complete |
| Performance | Near-native | Some overhead |
Windows
- Windows 10 64-bit: version 21H2 or higher (Home or Pro)
- WSL2 feature enabled (we'll do this in Step 4)
- Hardware virtualisation enabled in BIOS (usually on by default)
- At least 4 GB RAM (8 GB recommended)
Mac
- macOS 12 (Monterey) or later
- Intel chip or Apple Silicon (M1/M2/M3) โ Docker supports both
- At least 4 GB RAM
Download
Go to docker.com/products/docker-desktop and download the installer for your OS. Choose "Docker Desktop for Windows" (AMD64) or "Docker Desktop for Mac".
Install (Windows)
Run Docker Desktop Installer.exe. When asked, make sure "Use WSL2 instead of Hyper-V" is checked. Click OK. Installation takes a few minutes. A restart may be required.
Install (Mac)
Open the .dmg file, drag Docker to Applications, launch it. Accept the terms. Docker will ask for your Mac password to complete setup.
Sign In
Create a free account at hub.docker.com if you don't have one. Sign in from Docker Desktop. (A Docker Hub account lets you pull and push images.)
WSL2 lets you run a real Linux kernel inside Windows. Docker uses it as the container runtime on Windows โ this is faster and more compatible than the older Hyper-V approach.
Enable WSL feature
Open PowerShell as Administrator and run:
This installs WSL2 and Ubuntu by default. Restart your computer when prompted.
Set WSL2 as default
Verify WSL2
You should see Ubuntu with VERSION 2.
Open a terminal (or PowerShell on Windows) and run:
The classic hello-world
Docker pulls the hello-world image from Docker Hub and runs it. You'll see a message confirming Docker is working correctly.
Run an nginx web server
Open http://localhost:8080 in your browser โ you'll see the Nginx welcome page!
| Flag | Meaning |
|---|---|
-d | Detached mode โ run in background |
-p 8080:80 | Map port 8080 on your machine to port 80 in the container |
--name my-nginx | Give the container a friendly name |
nginx | The image name to use |
Stop and remove the container
| Command | What it does |
|---|---|
docker images | List all downloaded images |
docker ps | List running containers |
docker ps -a | List all containers (including stopped) |
docker pull <image> | Download an image from Docker Hub |
docker run <image> | Create and start a container |
docker stop <name> | Gracefully stop a container |
docker rm <name> | Remove a stopped container |
docker rmi <image> | Remove an image |
docker logs <name> | View container logs |
docker exec -it <name> bash | Open a shell inside a running container |
docker build -t myapp . | Build an image from a Dockerfile in the current directory |
Docker is an open-source platform for containerisation โ packaging an application and all its dependencies (OS libraries, config, runtime) into a single portable unit called a container.
We use Docker because it solves the "works on my machine" problem. The same container runs identically on a developer's laptop, a CI server, and production. It also enables fast startup, efficient resource usage, and easy scaling.
A Docker image is a read-only, static template โ like a blueprint or a recipe. It contains the filesystem layers needed to create a container. Images are built from a Dockerfile and stored in a registry (like Docker Hub).
A container is a running instance of an image โ like a house built from a blueprint. You can run many containers from the same image. Each container has its own writable layer on top of the shared image layers.
A Dockerfile is a plain text file with instructions that Docker uses to build an image. Each instruction creates a layer. Common instructions:
FROMโ base image to start fromWORKDIRโ set working directory inside the containerCOPYโ copy files from host to containerRUNโ execute a command while building the imageEXPOSEโ document which port the app listens onCMDโ the default command to run when the container starts
CMD provides default arguments that can be overridden when running the container. E.g., CMD ["java", "-jar", "app.jar"] โ but you can override it by passing a different command to docker run.
ENTRYPOINT defines the main executable that always runs. It cannot be overridden (only its arguments can). Use ENTRYPOINT when the container has a specific purpose and CMD for default arguments to that entrypoint.
Common pattern: ENTRYPOINT ["java"] + CMD ["-jar", "app.jar"]
docker-compose is a tool for defining and running multi-container Docker applications. You define all services (e.g., your Spring Boot app, PostgreSQL, Redis) in a docker-compose.yml file, then start everything with a single command: docker compose up.
It handles networking (all services can reach each other by name), volume mounts, environment variables, and port mappings โ all in one declarative file.
Containers are ephemeral โ when a container is removed, its data is lost. A volume is a way to persist data outside the container's lifecycle. Volumes are managed by Docker and exist on the host filesystem.
Example: For a PostgreSQL container, you mount a volume at /var/lib/postgresql/data so your database data survives container restarts and removals.