Run a packaged app in one command
One idea, one win: start a real web app someone else packaged, open it in your browser, then prove the image and the container are different things.
About 10 minutesWhen you ship with Docker, you will hand other people (or production servers) an image — a portable package of your app. They create a container from it. Today you play the role of the person receiving a package, so the words stop being abstract.
The mental model
A container is an isolated process for your app. It is self-contained, isolated from your Mac’s other software, and portable: the same package should behave the same way on your laptop and on a server.
An image is the read-only package that supplies the files, binaries, and config a container needs. One image can create many independent containers.
The package you pull
The running process
Primary source (read once, slowly): Docker’s own explanations of containers and images.
Do it: start the sample web app
Open Terminal. Docker Desktop must be running (whale icon in the menu bar). Then run:
docker run --detach --name my-first-app --publish 8080:80 docker/welcome-to-docker
What that does, in order:
docker run— create a container from an image and start it--detach— run in the background so you keep your terminal--name my-first-app— a friendly name instead of a random one--publish 8080:80— map your Mac’s port8080to the app’s port80inside the containerdocker/welcome-to-docker— the image name (pulled from Docker Hub if you don’t have it yet)
1. Prove the container is running
docker ps
What should I notice?
A row named my-first-app, image docker/welcome-to-docker, status starting with Up, and ports like 0.0.0.0:8080->80/tcp.
2. Open the app in a browser
open http://localhost:8080
Or visit http://localhost:8080. You should see the sample site served by the container — not by anything you installed with Homebrew.
3. Stop and remove the container
docker stop my-first-app
docker rm my-first-app
Stopping ends the process. Removing deletes that container. The image stays on disk.
4. Prove the lifecycles differ
docker ps --all
docker image ls docker/welcome-to-docker
Check your observation
my-first-app should be gone from the container list (or absent if you removed it). The docker/welcome-to-docker image should still appear. Refresh the browser: the site should no longer load.
Retrieve it from memory
You removed my-first-app. What can still create a new container?
Optional stretch (same idea, different image)
If you want one more rep without new theory, run the official Nginx image, then stop and remove it:
docker run --detach --name nginx-try --publish 8081:80 nginx:alpine
open http://localhost:8081
docker rm --force nginx-try
Same pattern: image → container → publish a port → clean up. The image name is the only real change.
Your checkpoint (reply to your teacher)
Without looking back, send two short answers in your own words:
- An image is …
- A container is …
Also say whether the sample site opened at localhost:8080. That tells us whether to reinforce this or move to building an image of an app you control.