โ† Back | Docker Desktop Setup
Pre-Course
Pre-Course ยท Setup

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 Desktop Windows / Mac / Linux WSL2 Enabled
๐Ÿง 
Concept
What is Docker and why does it matter?
Real-world analogy: Before shipping containers existed, loading cargo onto ships was chaotic โ€” every item had a different size and needed different handling. Shipping containers standardized everything: one standard box that fits on any ship, truck, or train.

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!"
ConceptReal-World EquivalentIn Docker
Docker ImageA recipe / blueprintRead-only template (built from Dockerfile)
Docker ContainerAn actual meal / productRunning instance of an image
DockerfileStep-by-step cooking instructionsFile that defines how to build an image
Docker HubA library of recipesPublic registry of Docker images
docker-composeA catering companyRuns multiple containers together

Container vs Virtual Machine

FeatureContainerVirtual Machine
Startup timeSecondsMinutes
SizeMBsGBs
OS included?No (shares host kernel)Yes (full OS)
IsolationProcess-levelComplete
PerformanceNear-nativeSome overhead
๐Ÿ“‹
Step 1
System Requirements

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
Check virtualisation (Windows): Open Task Manager โ†’ Performance tab โ†’ CPU. You should see "Virtualisation: Enabled". If Disabled, you need to enable it in your BIOS/UEFI settings.
๐Ÿณ
Step 2
Install Docker Desktop
1

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".

2

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.

3

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.

4

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.)

๐Ÿง
Step 3 โ€” Windows Only
Enable WSL2
Windows Subsystem for Linux 2 โ€” required for Docker on Windows

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.

1

Enable WSL feature

Open PowerShell as Administrator and run:

wsl --install

This installs WSL2 and Ubuntu by default. Restart your computer when prompted.

2

Set WSL2 as default

wsl --set-default-version 2
3

Verify WSL2

wsl --list --verbose

You should see Ubuntu with VERSION 2.

Docker Desktop will use WSL2 automatically once enabled. In Docker Desktop โ†’ Settings โ†’ Resources โ†’ WSL Integration, enable it for your Ubuntu distribution.
โœ…
Step 4
Verify Docker Installation

Open a terminal (or PowerShell on Windows) and run:

docker --version
Docker version 26.1.1, build 4cf5afa
docker-compose --version
Docker Compose version v2.27.0-desktop.2
Docker Desktop must be running in the background for these commands to work. Look for the whale icon in your system tray (Windows) or menu bar (Mac).
๐Ÿš€
Step 5
Run Your First Container
Hello World + a real web server

The classic hello-world

docker run 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

docker run -d -p 8080:80 --name my-nginx nginx

Open http://localhost:8080 in your browser โ€” you'll see the Nginx welcome page!

FlagMeaning
-dDetached mode โ€” run in background
-p 8080:80Map port 8080 on your machine to port 80 in the container
--name my-nginxGive the container a friendly name
nginxThe image name to use

Stop and remove the container

docker stop my-nginx docker rm my-nginx
โŒจ๏ธ
Reference
Essential Docker Commands
CommandWhat it does
docker imagesList all downloaded images
docker psList running containers
docker ps -aList 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> bashOpen a shell inside a running container
docker build -t myapp .Build an image from a Dockerfile in the current directory
๐ŸŽฏ
Interview Prep
Common Interview Questions
QWhat is Docker and why do we use it?

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.

QWhat is the difference between a Docker image and a container?

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.

QWhat is a Dockerfile?

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 from
  • WORKDIR โ€” set working directory inside the container
  • COPY โ€” copy files from host to container
  • RUN โ€” execute a command while building the image
  • EXPOSE โ€” document which port the app listens on
  • CMD โ€” the default command to run when the container starts
QWhat is the difference between CMD and ENTRYPOINT in a Dockerfile?

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"]

QWhat is docker-compose?

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.

QWhat is a Docker volume?

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.