Docker Assignment– 2
Docker Images & Networking
Basic Questions
- Create a simple Dockerfile that uses ubuntu as a base image and prints “Hello Docker”.
- Build an image from the Dockerfile and name it myimage:v1.
- List all images available on your system.
- Inspect an image and note its base layer.
- Build an image again with a small change and observe new layers.
- Tag an existing image with a new version number (e.g., myimage:v2).
- Remove a specific image tag without deleting the whole image.
- Save an image to a .tar file and reload it on another system.
- Run a container from your custom image.
- Create a bridge network named mynetwork.
- Run a container attached to mynetwork.
- List all networks in Docker.
- Inspect the bridge network and note its subnet.
- Run a container on the default bridge network and print its IP address.
- Expose port 8080 of a container to host port 8080.
- Map container port 5000 to host port 8000 and verify with curl.
- Run two containers in the same bridge network and ping one from the other.
- Run a container using the host network and note the difference from bridge.
- Run a container with a custom name and attach it to mynetwork.
- Remove an unused Docker network.
Intermediate Questions
- Create a Dockerfile that installs nginx and copies a custom index.html into it.
- Build the image and tag it as custom-nginx:v1.
- Run a container from custom-nginx:v1 and expose it on port 8080.
- Verify the running web app using a browser or curl localhost:8080.
- Modify the index.html, rebuild the image as v2, and run it again.
- Compare the layers between v1 and v2 images.
- Create a container from your image and connect it to both the default bridge and a custom network.
- Create a second container in the same network and access the first container by its name.
- Create and run a container using the macvlan driver and assign it a custom IP address.
- Create an overlay network (requires Docker Swarm) and verify its creation.
- Run a container with multiple ports exposed and map them to host.
- Use docker exec to install additional packages inside a running container and commit it as a new image.
- Tag your image with both latest and a version number.
- Push your custom image to Docker Hub.
- Pull your custom image from Docker Hub onto another system.
- Write a Dockerfile that sets environment variables and prints them.
- Build an image with a custom working directory.
- Build an image that runs a Python script printing “Hello from Docker”.
- Inspect the network of a running container and print its gateway.
- Disconnect a container from a network and reconnect it to another.
Advanced Questions
- Write a Dockerfile that builds a web app (Nginx serving a custom HTML page).
- Build and tag the web app image as mywebapp:v1.
- Create a custom bridge network named webapp-net.
- Run the mywebapp:v1 container attached to webapp-net and expose it on port 8080.
- Run a second container in webapp-net and access the web app using the container name.
- Add a second version of the app (v2) with modified content and run both versions simultaneously.
- Configure port mapping so v1 runs on port 8080 and v2 runs on port 9090.
- Run your web app container using the host network and compare accessibility.
- Deploy the web app containers in an overlay network (Swarm mode) and test cross-node communication.
- Document and demonstrate the full workflow: Write Dockerfile → Build custom image → Tag versions → Create custom network → Run multiple containers → Test connectivity and ports.