Experiment -2.
2
Student Name: Adarsh Kumar Singh UID: 22BDO10053
Branch: AIT-CSE-DevOps Section/Group: 22BCD-1(B)
Semester: 5th Date of Performance: 24-09-24
Subject Name: Docker and Kubernetes Subject Code: 22CSH-343
1. Aim/Overview of the practical:
To Setup
i. Container to WWW Communication,
ii. Container to Local Host Machine Communication,
iii. Container to Container Communication,
iv. Creating a Container & Communicating to the Web (WWW),
v. Container to Host Communication Work,
vi. Container to Container Communication using Docker Desktop.
2. Apparatus: PC, Docker Engine, DockerHub, Ubuntu Linux
3. Steps for experiment/practical:
Docker Networking: It allows you to create a Network of Docker Containers managed by a master node
called the manager.
1. Containers inside the Docker Network can talk to each other by sharing packets of information.
2. The Docker network is a virtual network created by Docker to enable communication between Docker
containers.
3. If two containers are running on the same network or host, they can communicate with each other without
the need for ports to be exposed to the host machine.
4. A network driver defines how containers interact with each other, with the host system, and with external
networks.
❖ Bridge (default)
Use Case: Containers on the same host.
How It Works: Containers connected to the same bridge network can communicate with
each other, but they are isolated from other networks by default. This is the default
driver if no network is specified when creating a container
❖ Host
Use Case: For cases where the container should share the host's network stack.
How It Works: The container uses the host’s network directly, which means it
doesn't get its own IP address. Instead, it shares the host's IP and ports.
❖ Overlay
Use Case: Multi-host Docker deployments, especially in Docker Swarm.
How It Works: Allows containers running on different hosts to communicate with
each other, using a distributed network across the Docker Swarm cluster. It creates
an encrypted network overlay over the physical infrastructure.
❖ Macvlan
Use Case: Direct communication with physical networks.
How It Works: Assigns a MAC address to each container, making it appear as a
physical device on the network. This is useful when you want to bypass the
Docker host’s network stack.
❖ None
Use Case: Total network isolation
How It Works: The container doesn’t get any network interface, effectively
isolating it from any network.
• Docker Network Commands
1. docker network create --driver<driver-name> <network-name>.
2. docker network ls
3. docker network connect <network-name> <container-name>
4. docker network inspect <network-name>
5. docker network disconnect <network-name> <container-name>
6. docker network rm <network-name>
7. docker network prune
• Container to WWW Communication
1. Pull a Nginx image from Docker Hub to create a web server container.
2. Create a Docker container using the Nginx image
3. Access the default webpage running inside the container using https://localhost:80
• Container to Local Host Machine Communication
1. Identify the service running on the host machine that you want to communicate with
from the container. Have the default web-page of nginx running on the host machine
2. Determine the IP address of the host machine.
Create a Docker container and configure it to communicate with the host machine.
Test the container's communication with the host machine. Run the following command to access a service
(e.g., a web server) running on the host machine from within the container:
docker exec my_local_app curl http://host_machine_IP
• Container to Container Communication
1. Create two Docker containers that need to communicate with each other:
2. Create a user-defined bridge network and attach both containers to the user-defined network:
3. Verify that both containers are connected to the same network. Both the containers would be visible under
containers when we inspect the docker network.
4. the communication between the containers by pinging b/w them. Send 4 packets by docker exec
<container_name> ping -c 4 <container_name>
• Creating a Container & Communicating to the Web (WWW)
1. Create a Docker container using Nginx image
2. Access the web server running inside the container at the address http://localhost:80/
3. If everything is set up correctly, you should see the default Nginx welcome page in your web browser.
• Container to Host Communication Work
1. Identify the service running on the host machine that you want to communicate with from the
container. For this, a web-server running on nginx on the host machine.
2. Create a Docker container and configure it to communicate with the host service.
3.
4. Access the service running on the host from the container
a. Inside the container, you can now access the web server running on the host machine using the
host IP address and the mapped port (8080).
Learning outcomes (What I have learnt):
1. I have learnt the concept of containerization.
2. I have learnt to configure Docker to work with different environments.
3. I have learnt how to build docker images using Dockerfile.
4. I have learnt the purpose of Dockerfile and its advantages.
5. I have learnt how Dockerfile can help in creating CI/CD pipelines.
6. Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):
Sr. No. Parameters Marks Obtained Maximum Marks
1.
2.
3.