DOCKER / LESSON 03
Essential Docker Commands.
Learn the core Docker commands for running, managing, and debugging containers

Loading the lesson…
Loading activities…
DOCKER / LESSON 03
Learn the core Docker commands for running, managing, and debugging containers

Loading the lesson…
Loading activities…
Okay, enough theory. Time to get your hands dirty. This lesson walks through the commands you'll reach for over and over when you're working with Docker, and by the end you'll be building, running, inspecting and cleaning up containers without breaking a sweat.
You can't run a container without an image first. The docker build command makes an image from a Dockerfile (you'll write your own next lesson).
The -t flag gives your image a name (and a tag if you want one). That lil . at the end tells Docker to use the folder you're sitting in right now as the build context, which is also where it looks for the Dockerfile unless you say otherwise.
The docker run command creates a brand new container from an image and starts it up.
docker run Flags| Flag | Purpose | Example |
|---|---|---|
-d | Run in background (detached) | docker run -d myapp |
-p | Map ports | docker run -p 8080:3000 myapp |
--name | Give the container a name | docker run --name web myapp |
-e | Set environment variables | docker run -e NODE_ENV=production myapp |
--rm | Automatically remove when stopped | docker run --rm myapp |
-it | Interactive mode with terminal | docker run -it node:24-alpine sh |
Want to know what's running? That's docker ps.
When something breaks (or you're just nosy about what your app is up to), check the logs.
Every now and then you need to climb inside a running container to poke at files, check a config or chase down a bug.
The -it flags give you an interactive terminal, so you can type commands like you're standing right inside the container.
Done with a container? Here's how you shut it down and clear it out.
You can download images from Docker Hub without running them.
Here's what a normal day of developing with Docker usually looks like, start to finish.
Screenshot this one. You WILL be back.
| Command | What It Does |
|---|---|
docker build -t name . | Build an image from a Dockerfile |
docker run -d -p 3000:3000 image | Run a container in the background |
docker ps | List running containers |
docker logs container | View container output |
docker exec -it container sh | Open a shell inside a container |
docker stop container | Gracefully stop a container |
docker rm container | Remove a stopped container |
docker pull image:tag | Download an image from a registry |
docker images | List local images |
docker build makes images, and docker run makes containers from those images-p host:container to map ports and -d to run in the backgrounddocker ps shows running containers, and docker logs shows what they printeddocker exec -it drops you into a shell inside a running containerdocker rm so they quit eating disk spaceYou've been building images with docker build this whole time, but where do the build instructions actually come from? Next lesson you'll write your own Dockerfile, the recipe that tells Docker exactly how to build your app's image...