Docker Assignment– 2

Docker Images & Networking

Basic Questions

  1. Create a simple Dockerfile that uses ubuntu as a base image and prints “Hello Docker”.
  2. Build an image from the Dockerfile and name it myimage:v1.
  3. List all images available on your system.
  4. Inspect an image and note its base layer.
  5. Build an image again with a small change and observe new layers.
  6. Tag an existing image with a new version number (e.g., myimage:v2).
  7. Remove a specific image tag without deleting the whole image.
  8. Save an image to a .tar file and reload it on another system.
  9. Run a container from your custom image.
  10. Create a bridge network named mynetwork.
  11. Run a container attached to mynetwork.
  12. List all networks in Docker.
  13. Inspect the bridge network and note its subnet.
  14. Run a container on the default bridge network and print its IP address.
  15. Expose port 8080 of a container to host port 8080.
  16. Map container port 5000 to host port 8000 and verify with curl.
  17. Run two containers in the same bridge network and ping one from the other.
  18. Run a container using the host network and note the difference from bridge.
  19. Run a container with a custom name and attach it to mynetwork.
  20. Remove an unused Docker network.

Intermediate Questions

  1. Create a Dockerfile that installs nginx and copies a custom index.html into it.
  2. Build the image and tag it as custom-nginx:v1.
  3. Run a container from custom-nginx:v1 and expose it on port 8080.
  4. Verify the running web app using a browser or curl localhost:8080.
  5. Modify the index.html, rebuild the image as v2, and run it again.
  6. Compare the layers between v1 and v2 images.
  7. Create a container from your image and connect it to both the default bridge and a custom network.
  8. Create a second container in the same network and access the first container by its name.
  9. Create and run a container using the macvlan driver and assign it a custom IP address.
  10. Create an overlay network (requires Docker Swarm) and verify its creation.
  11. Run a container with multiple ports exposed and map them to host.
  12. Use docker exec to install additional packages inside a running container and commit it as a new image.
  13. Tag your image with both latest and a version number.
  14. Push your custom image to Docker Hub.
  15. Pull your custom image from Docker Hub onto another system.
  16. Write a Dockerfile that sets environment variables and prints them.
  17. Build an image with a custom working directory.
  18. Build an image that runs a Python script printing “Hello from Docker”.
  19. Inspect the network of a running container and print its gateway.
  20. Disconnect a container from a network and reconnect it to another.

Advanced Questions

  1. Write a Dockerfile that builds a web app (Nginx serving a custom HTML page).
  2. Build and tag the web app image as mywebapp:v1.
  3. Create a custom bridge network named webapp-net.
  4. Run the mywebapp:v1 container attached to webapp-net and expose it on port 8080.
  5. Run a second container in webapp-net and access the web app using the container name.
  6. Add a second version of the app (v2) with modified content and run both versions simultaneously.
  7. Configure port mapping so v1 runs on port 8080 and v2 runs on port 9090.
  8. Run your web app container using the host network and compare accessibility.
  9. Deploy the web app containers in an overlay network (Swarm mode) and test cross-node communication.
  10. Document and demonstrate the full workflow: Write Dockerfile → Build custom image → Tag versions → Create custom network → Run multiple containers → Test connectivity and ports.