This practical demonstrates how containerized applications can be executed dynamically using Docker volume mounting.
Instead of rebuilding a Docker image every time the application code changes, the source code from the host machine is mounted directly inside the running container.
This allows developers to modify the application on their local system while the container accesses the latest version instantly.
This concept represents a real-world DevOps development workflow, where container environments are used for development, testing, and runtime execution without rebuilding images repeatedly.
| Technology | Description |
|---|---|
| Docker Desktop | Container runtime platform |
| Docker CLI | Command line interface for Docker |
| GCC Compiler | GNU C compiler used inside container |
| C Programming Language | Application code |
| Docker Volume Mount | Host and container file sharing |
| Windows Command Prompt | Command execution environment |
| Linux Runtime (Container) | Execution environment inside Docker |
Class Practical 6 Feb
│
├── app.c
└── Dockerfile
This application asks the user to enter their SAP ID continuously.
The program contains:
• A stored SAP ID
• A user input SAP ID
• A comparison logic using strcmp()
• A continuous while(1) loop for runtime interaction
The program continues running indefinitely until the container is manually stopped.
#include <stdio.h>
#include <string.h>
int main() {
char stored_sapid[] = "500121943";
char user_sapid[50];
while (1) {
printf("Enter your SAP ID: ");
scanf("%s", user_sapid);
if (strcmp(user_sapid, stored_sapid) == 0) {
printf("Matched\n");
}
else {
printf("Not Matched\n");
}
}
return 0;
}
The Dockerfile defines how the container environment should be built.
In this case we use the official GCC base image so that the container has a C compiler available.
The program will be compiled and executed inside the container runtime.
FROM gcc:latest
WORKDIR /app
CMD ["bash", "-c", "gcc app.c -o app && ./app"]
Navigate to the project directory and build the image.
docker build -t sapid-checker .
This command:
• Reads the Dockerfile
• Pulls the GCC base image if not available
• Creates a new Docker image called sapid-checker
docker images
Expected Output:
REPOSITORY TAG IMAGE ID CREATED SIZE
sapid-checker latest XXXXXXXX XX seconds ago XXXMB
This confirms the Docker image was successfully built.
Now we mount the host application file inside the container.
docker run -it -v "%cd%/app.c:/app/app.c" sapid-checker
Explanation:
-it
Interactive terminal mode
-v "%cd%/app.c:/app/app.c"
Maps the host file to container file
HOST FILE CONTAINER FILE
app.c → /app/app.c
This means:
Any change to app.c on the host system will immediately reflect inside the container.
Once the container starts, the following command runs automatically:
gcc app.c -o app && ./app
Steps performed inside container:
Enter your SAP ID: 123456
Not Matched
Enter your SAP ID: 500121943
Matched
The application continues running due to the infinite loop.
To stop execution:
CTRL + C
This terminates the container process.
• Official Docker Base Image
• Containerized Compilation
• Runtime File Injection
• Docker Volume Mounting
• Host ↔ Container File Sharing
• Interactive Containers
• Continuous Runtime Execution
• Development Without Image Rebuild
Traditional Workflow
Edit Code
Rebuild Image
Run Container
Docker Volume Workflow
Edit Code
Run Container
Changes Reflect Instantly
This significantly improves developer productivity.
This technique is commonly used in:
• Software development environments
• Containerized testing pipelines
• Continuous Integration systems
• DevOps microservice development
• Cloud native container workflows
Developers often mount source code directly inside containers to test applications without rebuilding Docker images repeatedly.
Successfully executed a C application inside a Docker container using volume mounting and continuous runtime execution.
The application compiled and ran inside the container while reading the source file directly from the host system.
This practical demonstrated how Docker can be used to run and test applications dynamically using volume mounts.
Instead of embedding the source code inside the container image, the program was executed using files mounted from the host system.
This approach enables rapid development, faster testing cycles, and efficient container-based workflows commonly used in modern DevOps environments.