0
0
Dockerdevops~30 mins

Bind mounts for development in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Bind mounts for development
📖 Scenario: You are working on a web application project. You want to run your app inside a Docker container but keep your code on your computer. This way, when you change your code, the container sees the changes immediately without rebuilding.
🎯 Goal: Learn how to use Docker bind mounts to link your local project folder to a folder inside the container for easy development.
📋 What You'll Learn
Create a Docker container running a simple web server
Use a bind mount to connect your local project folder to the container
Verify that changes in your local files reflect inside the container
💡 Why This Matters
🌍 Real World
Developers often use bind mounts to work on code locally while running it inside containers. This speeds up testing and debugging.
💼 Career
Knowing how to use bind mounts is essential for DevOps roles and developers working with Docker in real projects.
Progress0 / 4 steps
1
Create a simple Docker container
Write a docker run command to start a container named webdev using the nginx image. Run it in detached mode with port 8080 on your computer mapped to port 80 inside the container.
Docker
Need a hint?

Use docker run -d --name webdev -p 8080:80 nginx to start the container.

2
Add a bind mount to link your local folder
Modify the docker run command to add a bind mount. Mount your local folder /home/user/myapp to /usr/share/nginx/html inside the container. Keep the container name webdev, detached mode, and port mapping the same.
Docker
Need a hint?

Add -v /home/user/myapp:/usr/share/nginx/html to the docker run command.

3
Restart the container with the bind mount
Stop and remove the existing webdev container. Then run the updated docker run command with the bind mount from Step 2 to start the container again.
Docker
Need a hint?

Use docker stop webdev and docker rm webdev to remove the old container before running the new one.

4
Verify bind mount works by checking container files
Run a command inside the webdev container to list the files in /usr/share/nginx/html. Use docker exec with ls -l /usr/share/nginx/html. Print the output.
Docker
Need a hint?

Use docker exec webdev ls -l /usr/share/nginx/html to see the files inside the container folder.