Container foundations
Run and inspect a container
Start a web server container, publish its port, inspect its state, read its logs, and remove it deliberately.
8 minute lesson
Run a known image before building your own. This separates Docker basics from application build problems.
--name gives the container a stable local name, -d runs it in the background, and -p 8080:80 forwards host port 8080 to container port 80. Port publishing is explicit: a process listening inside a container is not automatically reachable from the host.
docker run --name course-web -d -p 8080:80 nginx:alpine
docker ps
docker logs course-web
docker inspect course-web
docker rm -f course-web
The lifecycle has separate steps even when docker run combines them: create a container, start its main process, stop it, and remove it. A stopped container can be inspected and started again, but its writable layer remains tied to that particular container. Removing it does not remove the image or an independently managed volume.
Use docker inspect for configured and runtime state, and docker logs for what the main process wrote to standard output and standard error. If the main process exits, start with its exit code and logs. An interactive shell is secondary evidence and is unavailable when the container is stopped.
Open http://localhost:8080, find the image name and port mapping in docker ps, then remove the container.
Lesson completed