In this lab, you will:
- Run Docker containers
- Explore container networking
- Create and use a custom bridged network
- Inspect container IP addresses
- Test connectivity between containers
- Deploy a web server (nginx)
- Validate your work using an automated check script
- Fork this repository to your GitHub account.
- Navigate to your forked repository and select: Code → Codespaces → Create codespace
- Wait for the environment to start.
Note: Docker is pre-installed in this Codespace. You do not need to install Docker manually. The environment is ready for container networking tasks.
What these commands do:
docker --versionshows the installed Docker version to confirm Docker is available.docker pslists running containers (should be empty at first).
docker --version
docker psWhat these commands do:
docker pull ubuntu:focaldownloads the Ubuntu image (version focal) from Docker Hub so you can use it for containers.docker imageslists all images available locally, including the one you just pulled.
docker pull ubuntu:focal
docker imagesWhat these commands do:
docker network create --driver bridge csf-netcreates a new custom bridge network namedcsf-netfor your containers to use. This network isolates your containers from others and lets you control their communication.docker network lslists all Docker networks, so you can confirm your new network was created.
docker network create --driver bridge csf-net
docker network lsWhy?
A user-defined bridge network (csf-net) allows containers to communicate securely and predictably. Unlike the default bridge, it provides better network isolation and lets you control which containers can talk to each other. This is important for container security, as it limits exposure and enables network segmentation—key principles in secure container deployments.
What this command does:
docker run -it -d --name csf-ubuntu1 --network csf-net ubuntu:focalstarts a new Ubuntu container namedcsf-ubuntu1in the background, attached to thecsf-netnetwork. The-itallows interactive mode, and-druns it detached (in the background).
docker run -it -d --name csf-ubuntu1 --network csf-net ubuntu:focalWhat this command does:
docker run -it -d --name csf-ubuntu2 --network csf-net ubuntu:focalstarts a second Ubuntu container namedcsf-ubuntu2, also attached to thecsf-netnetwork, so it can communicate with the first container.
docker run -it -d --name csf-ubuntu2 --network csf-net ubuntu:focalWhat this command does:
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' csf-ubuntu1shows the internal IP address of thecsf-ubuntu1container on the custom network. You will use this IP to test connectivity.
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' csf-ubuntu1Save this IP address for later use.
What this command does:
docker exec -it csf-ubuntu2 /bin/bashopens a shell inside thecsf-ubuntu2container so you can run commands inside it.
docker exec -it csf-ubuntu2 /bin/bashWhat this command does:
apt-get updaterefreshes the list of available software packages inside the container, so you can install new tools.
apt-get updateWhat this command does:
apt-get install iputils-ping -yinstalls thepingtool inside the container, which is needed to test network connectivity. The-yflag auto-confirms the install.
apt-get install iputils-ping -yWhat this command does:
ping <IP_ADDRESS>sends network test packets to the IP address of the first container. If you see replies, the containers can communicate over the custom network.
Replace <IP_ADDRESS> with the value from Step 5. You should see successful replies.
Exit the container shell with:
exitWhat this command does:
docker run -d -p 8080:80 --name csf-nginx nginx:lateststarts an Nginx web server container namedcsf-nginx, mapping port 8080 on your Codespace to port 80 in the container. The-dflag runs it in the background.
docker run -d -p 8080:80 --name csf-nginx nginx:latestWhat to do:
- Go to the Ports tab in Codespaces.
- Open port 8080.
- You should see: "Welcome to nginx!"
Run the check script:
bash check.shThis will generate a marksheet.md file with your GitHub username and a summary of your lab checks. Your instructor will use this for grading.