Peters School of Business · Assiniboine College · NETW-0014
2 hours · Lab 6B · docker run -p and -v, docker logs, docker exec, networks
Lab 6B — Port mapping, bind mounts, logs, exec, and Docker networking
Part 1 — Port mapping with Nginx (20 min)
docker run -d -p 8080:80 --name webserver nginx
curl http://localhost:8080 — should return Nginx welcome HTML. From Windows browser: http://[S1-external-IP]:8080 — same result.docker logs webserver — shows Nginx access log entries for each request. Follow live: docker logs -f webserver. Press a browser refresh and watch the entry appear.docker inspect webserver. Find in the output: the container's internal IP address (typically 172.17.x.x), the port mapping, the image used, the mount points.Part 2 — Bind mounts (-v) for persistent content (25 min)
mkdir -p ~/webroot && echo "<h1>Served from a bind mount</h1>" > ~/webroot/index.html
docker stop webserver && docker rm webserver
docker run -d -p 8080:80 --name webserver -v ~/webroot:/usr/share/nginx/html:ro nginx
curl http://localhost:8080 — returns the custom HTML. Modify ~/webroot/index.html on the host and refresh — the change appears immediately without restarting the container. The bind mount is a live link.Part 3 — docker exec for live debugging (15 min)
docker exec -it webserver bash
ps aux — only Nginx processes. Run cat /etc/nginx/nginx.conf. Run ls /usr/share/nginx/html — see the bind-mounted index.html. Exit with exit — the container keeps running.
Part 4 — Custom Docker network address range (15 min)
sudo nano /etc/docker/daemon.json
{
"default-address-pools": [
{"base": "10.10.0.0/16", "size": 24}
]
}
sudo systemctl restart docker. New containers now use the 10.10.0.x range.
docker inspect [container] | grep IPAddress — should show a 10.10.x.x address.Part 5 — Running an Ubuntu container on a custom network (25 min)
docker network create --driver bridge mynet
docker network ls — shows the new network alongside bridge, host, none.
docker run -d -it --name ubuntu1 --network mynet ubuntu bash
docker run -d -it --name ubuntu2 --network mynet ubuntu bash
docker exec -it ubuntu1 bash
ping ubuntu2
Learning outcomes — by end of Day 2, students can…
Common issues and fixes
| Issue | Likely cause | Fix |
|---|---|---|
| docker run -p 8080:80 fails — port already in use | Nginx is running on the host on port 8080, or a previous container still mapped to it | Stop the host Nginx: sudo systemctl stop nginx. Or use a different host port: -p 8081:80. Stop any other container using 8080: docker ps, then docker stop [container] |
| Bind mount shows wrong content or empty directory | Host path doesn't exist, or wrong path specified | Verify the host path exists: ls -la ~/webroot/. Paths in -v must be absolute or use ~ (which expands to /home/student). Check: docker inspect [container] | grep Mounts |
| daemon.json change not taking effect | Docker not restarted after editing, or JSON syntax error | Validate JSON: python3 -m json.tool /etc/docker/daemon.json. Restart: sudo systemctl restart docker. Check: sudo systemctl status docker |