GUIDE 17 / CONTAINERS
Docker
Inspect images, containers, published ports, and read-only host mounts.
Commands use class paths and example filenames. Replace placeholders and inspect the target before making changes.
Inspect containers and images
An image is a template; a container is a running or stopped instance of an image. Containers share the host kernel, while virtual machines run their own guest kernels.
docker version
docker image ls
docker ps -a
docker logs --tail 20 hw8-public
docker port hw8-public 80Access to the Docker daemon is highly privileged. A user in the docker group can effectively gain root access to the host. Container names must be unique, including stopped containers.
Understand published ports
127.0.0.1:8081 binds a host port only to loopback. A publication without a host IP usually binds all host interfaces. Docker may install DNAT and forwarding rules that make a port reachable independently of firewalld’s public-zone port list.
docker ps --format "table {{.Names}}\t{{.Ports}}"
curl -I http://127.0.0.1:8081
curl -I http://localhost:8888
sudo nft list rulesetIn the class setup, hw8-local is loopback-only on 8081 and hw8-public is exposed on 8888. Do not flush nftables or edit Docker-managed tables to diagnose this.
Keep content on the host
A bind mount exposes a host directory inside a container. :ro prevents container processes from writing through that mount; you can still edit the host files normally.
docker inspect hw8-public --format "{{json .Mounts}}"
docker exec hw8-public ls -l /usr/share/nginx/html
docker logs hw8-public 2>&1 | grep " 404 "Both class web containers read ~/homework/week8/site. Host edits appear in both without rebuilding an image. Removing a container does not delete that bind-mounted host directory.