Verified6 commandsAI-assisted
Images & Containers
Verified against Docker 29.1.5, flags verified via `docker <cmd> --help`, 2026-08-20 · official docs
Building and tagging images, and running/inspecting/cleaning up containers — the day-to-day loop of local container development.
Building images#
docker build -t myapp:latest . docker build -t myapp:v1.2.0 -f Dockerfile.prod . docker build --no-cache -t myapp:latest . # ignore layer cache, force a full rebuild docker build --build-arg NODE_ENV=production -t myapp:latest .
docker build is now backed by BuildKit (docker buildx build under the hood) — --no-cache invalidates every layer, while a targeted fix is usually cheaper: touching the file that changed and letting the layer cache do its job from that point forward.
Tagging and pushing images#
docker tag myapp:latest myregistry.io/myteam/myapp:v1.2.0 docker push myregistry.io/myteam/myapp:v1.2.0 docker pull myregistry.io/myteam/myapp:v1.2.0 docker images # list local images docker rmi myapp:latest # remove a local image
Running containers#
docker run -d --name my-app -p 8080:80 myapp:latest docker run -d --name my-app -e LOG_LEVEL=info -v ./data:/app/data myapp:latest docker run --rm -it myapp:latest /bin/bash # interactive, auto-removed on exit docker run -d --restart unless-stopped myapp:latest
-p 8080:80 maps host:container — the host port comes first. Getting this backwards is a common cause of "it works when I exec in but not from the browser."
Listing and inspecting containers#
docker ps # running containers only docker ps -a # include stopped containers docker ps --filter status=exited docker inspect my-app # full container config as JSON docker stats # live CPU/memory/network usage
Logs and exec#
docker logs my-app docker logs -f my-app # follow/stream docker logs --tail 100 --since 1h my-app docker exec -it my-app /bin/bash # interactive shell in a running container docker exec my-app env # one-off command, no shell
Stopping and removing containers#
docker stop my-app docker rm my-app docker rm -f my-app # stop and remove in one step docker container prune # remove all stopped containers