DevOps Virtualization and Configuration Management
DevOps Virtualization and Configuration Management
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:
FROM python:3.9
WORKDIR /appCOPY . .
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
EXPOSE 5000
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:
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:
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:
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:
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:
1.
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:
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:
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:
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:
Solution:
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.
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.
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
docker-compose up -d
Q3:
Solution:
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.
services:
frontend:
image: my-frontend
deploy:
replicas: 3
ports:
- "3000:3000"
docker-compose up -d
Solution:
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:
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:
Docker Swarm will perform a rolling update, ensuring that the service remains
available.
Solution:
Solution:
Solution:
Solution:
docker network ls
docker network connect my-network container1
1.
Solution:
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'
}
}
}
}
}
}