Day 2: Install Docker Desktop and Launch Your First Container in 5 Minutes
This guide walks through installing Docker Desktop on macOS, verifying the installation, optionally configuring registry mirrors, then demonstrates running the hello‑world image, launching an interactive Ubuntu container, and starting NGINX in detached mode with port mapping, explaining each command and flag.
Day 1 covered the concepts; today we install Docker Desktop.
Docker Desktop can be installed on macOS either by downloading the installer from the official Docker documentation ( https://docs.docker.com/get-docker/) or via Homebrew with the command: brew install --cask docker After installation the Docker whale icon appears in Launchpad and a Docker icon shows in the menu bar; the first launch may prompt for a login (optional).
Verify the installation:
docker --version
# Docker version 29.4.0, build ...
docker compose version
# Docker Compose version v5.1.3For faster image pulls in China, open Docker Desktop → Settings → Docker Engine and add a registry-mirrors array, for example:
{
"registry-mirrors": [
"https://docker.1ms.run",
"https://docker.xuanyuan.me"
]
}Click Apply & Restart to apply the mirrors.
Run Your First Container
docker run hello-worldThe output shows:
Hello from Docker!
This message shows that your installation appears to be working correctly.What happens: docker run checks whether the hello‑world image exists locally.
If not, Docker pulls the image from Docker Hub.
Docker creates a container from the image and runs it.
Interactive Containers
To start a container and get a shell inside it:
# Create a container and enter bash
docker run -it ubuntu bash
# Exit the container
exitFlags: -i: keep STDIN open (interactive mode). -t: allocate a pseudo‑TTY.
Note: after exit the container stops; use -d to run it detached.
Run NGINX in the Background
# Start NGINX detached and map ports
docker run -d -p 8080:80 nginx
# Verify it is running
docker ps
# Open a browser at http://localhost:8080Flags: -d: run container in detached (background) mode. -p 8080:80: map host port 8080 to container port 80.
Day 2 Summary
Docker Desktop is the standard development tool. docker run hello-world = pull image + create container + run. -it for interactive mode, -d for background, -p for port mapping.
Next up on Day 3: the three essential image commands – pull, images, and rm.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Tech Ocean
Focused on AI programming, sharing ready-to-use development efficiency solutions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
