0% found this document useful (0 votes)
12 views10 pages

DevOps Virtualization and Configuration Management

The document provides practical viva questions and solutions related to Docker, covering topics such as creating Docker containers, installing Docker on different systems, managing Docker images, deploying applications using Docker Compose, and setting up Docker Swarm. It includes step-by-step instructions for various scenarios, such as linking containers, scaling services, and configuring Continuous Integration with Jenkins. Overall, it serves as a comprehensive guide for understanding and implementing Docker in development and deployment processes.

Uploaded by

ysjaglak6093
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views10 pages

DevOps Virtualization and Configuration Management

The document provides practical viva questions and solutions related to Docker, covering topics such as creating Docker containers, installing Docker on different systems, managing Docker images, deploying applications using Docker Compose, and setting up Docker Swarm. It includes step-by-step instructions for various scenarios, such as linking containers, scaling services, and configuring Continuous Integration with Jenkins. Overall, it serves as a comprehensive guide for understanding and implementing Docker in development and deployment processes.

Uploaded by

ysjaglak6093
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

DevOps Virtualization and

Configuration Management -
Practical Viva Questions
Unit I: Introduction to Docker
Q1:

Your team is setting up a Docker environment for developing a web application. The
application needs to run on a specific version of Python (3.9). How would you create
a Docker container for this application?

Solution:

Create a Dockerfile specifying the Python version:

FROM python:3.9
WORKDIR /appCOPY . .
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
EXPOSE 5000

Build the Docker image:

docker build -t python-app .

Run the container:

docker run -p 5000:5000 python-app

Q2:

You need to install Docker on both Windows and Linux systems for a team of
developers. How would you ensure that Docker runs on both systems without any
issues?

Solution:

1.

For Windows:
1. Install Docker Desktop from the official Docker website.Enable
2. Windows Subsystem for Linux (WSL 2) as Docker relies on it.
3. Run Docker Desktop and verify with:

docker --version

For Linux:

Install Docker using the package manager. For example, on Ubuntu:

sudo apt-get update


sudo apt-get install docker-ce docker-ce-cli
containerd.io

Verify the installation:

docker --version

Q3:

A developer has made some updates to a Docker container and wants to save those
changes as a new image. How would you commit the changes and push the new
image to Docker Hub?

Solution:

Commit the changes in the container:

docker commit <container_id> username/new-app-


image

Push the image to Docker Hub:

docker login
docker push username/new-app-image

Q4:

You need to deploy a Dockerized application on a Linux machine, and you want it to
start automatically when the system reboots. How would you configure this?

Solution:

1.
Use Docker’s built-in restart policies when running the container:

docker run --restart=unless-stopped -d my-app

This ensures the container restarts automatically unless explicitly stopped.

Unit II: Basic Docker Operations


Q1:

You have a Node.js application and want to push it to Docker Hub after building the
Docker image. How would you push your application’s Docker image to Docker Hub?

Solution:

Tag the image for Docker Hub:

docker tag node-app username/node-app:latest

Push the image:

docker login
docker push username/node-app:latest

Q2:

You need to link a MySQL database container to a web application container. How
would you set up Docker to ensure that the two containers can communicate with
each other?

Solution:

Create a Docker network:

docker network create my-network

Run MySQL container connected to the network:

docker run --network my-network --name mysql-db -e


MYSQL_ROOT_PASSWORD=rootpassword -d mysql

1.

Run the web application container connected to the same network:


docker run --network my-network --name web-app -p 8080:80
my-web-app

Now, the web app can access MySQL using the hostname mysql-db.

Q3:

You want to update the code inside a running Docker container without rebuilding
the image. How would you achieve this?

Solution:

Use docker exec to access the container:

docker exec -it <container_id> /bin/bash

Once inside the container, you can modify the files as needed (e.g., updating code,
installing dependencies).

After making changes, you can commit the container to create a new image:

docker commit <container_id> username/updated-app

Q4:

You have a Docker container running a web application on port 8080. How would
you map the container’s port to your local machine’s port?

Solution:

1.

Use the -p flag to map container ports to host ports when running the container:

docker run -p 8080:8080 my-web-app

This maps port 8080 in the container to port 8080 on your local machine, so the
application is accessible via http://localhost:8080.
Unit III: Microservices and Docker
Compose
Q1:

You need to deploy a multi-container application consisting of a front-end (React


app) and back-end (Node.js API) using Docker Compose. How would you configure
Docker Compose for this setup?

Solution:

Create a docker-compose.yml file:

version: '3'services:
frontend:
build: ./frontend
ports:
- "3000:3000"
backend:
build: ./backend
ports:
- "5000:5000"

Inside the frontend and backend directories, include the respective Dockerfile for
building images.

Run the application using:

docker-compose up --build

Q2:

You want to deploy a WordPress website with a MySQL database using Docker
Compose. How would you configure Docker Compose for this?

Solution:

1.

Create a docker-compose.yml file:

version: '3'services:
wordpress:
image: wordpress
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: example
db:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: example

Run the application:

docker-compose up -d

Q3:

You need to deploy a microservices-based application where one service


(authentication) depends on another service (user management). How would you
configure Docker Compose to ensure these services communicate?

Solution:

Create a docker-compose.yml file:

version: '3'services:
auth-service:
image: auth-service
ports:
- "5001:5001"
user-service:
image: user-service
ports:
- "5002:5002"
depends_on:
- auth-service

This configuration ensures that the user-service starts after the auth-
service and both services can communicate.

Q4:
You want to scale a service in a Docker Compose application. How would you scale
the frontend service to 3 replicas?

Solution:

1.

Modify the docker-compose.yml file to include the replicas field under


the frontend service:

services:
frontend:
image: my-frontend
deploy:
replicas: 3
ports:
- "3000:3000"

Use Docker Compose to deploy the updated service:

docker-compose up -d

Unit IV: Container Orchestration

Q1 Scenario: You need to create a Docker Swarm cluster and


deploy a service with 3 replicas. How would you achieve this?

Solution:

Initialize the Docker Swarm

docker swarm init

Create the service with 3 replicas:

docker service create --name my-service --replicas 3 -p


8080:80 nginx

1.
2.

Q2:
Scenario: One of your services in Docker Swarm is not
performing well. How would you check the status of the
service and view its logs?

Solution:

Check the service status:

docker service ps my-service

View the logs of a container running the service:

docker logs <container_id>

Q3: Scenario: You need to update the image for a service running
in Docker Swarm. How would you do this without disrupting the
service?

Solution:

Update the service:

docker service update --image new-image:latest my-service

Docker Swarm will perform a rolling update, ensuring that the service remains
available.

Q4: Scenario: You want to scale a service in Docker Swarm from 3


replicas to 5 replicas. How would you do this?

Solution:

Scale the service: docker service scale my-service=5


Unit V: Docker Networks and CI

Q1:Scenario: You need to set up a Docker network so that multiple


containers can communicate securely. How would you do this?

Solution:

Create a custom network:

docker network create my-network

Run containers connected to this network:

docker run --network my-network --name container1 my-


image
docker run --network my-network --name container2 my-
image

Q2: Scenario: You want to connect two containers on different


Docker networks. How would you achieve this?

Solution:

Connect the containers to a common network:

docker network connect my-network container1


docker network connect my-network container2

Q3: Scenario: A Docker container is unable to connect to another


container. How would you troubleshoot and fix the networking
issue?

Solution:

Ensure both containers are on the same network:

docker network ls
docker network connect my-network container1
1.

Check firewall settings or other network restrictions that might prevent


communication.

Q4:Scenario: You want to set up Continuous Integration (CI) for


your Dockerized application. How would you configure this using
Jenkins?

Solution:

Install Jenkins and configure the Docker plugin.

Create a Jenkins Pipeline that builds the Docker image and runs tests:

pipeline {
agent any
stages {
stage('Build') {
steps {
script {
docker.build('my-image')
}
}
}
stage('Test') {
steps {
script {
docker.image('my-image').inside {
sh 'npm test'
}
}
}
}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy