By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Bind mounts allow you to mount a host directory into a Docker container, making files and directories accessible from within the container. -v /host/path:/container/path
mkdir /host/path
docker run -it -v /host/path:/container/path myimage
docker exec -it <container_id> ls /container/path
docker stop <container_id>
docker rm <container_id>
Purpose: To allow a developer to work on code in a container.Command: docker run -it -v /home/user/project:/project myimage Flags: -v mounts the host directory, -it allows interactive shell.
docker run -it -v /home/user/project:/project myimage
-v
-it
Purpose: To store data in a container without losing it when the container is deleted.Command: docker run -d -v /data:/data myimage Flags: -d runs the container in detached mode, -v mounts the host directory.
docker run -d -v /data:/data myimage
-d
Purpose: To store configuration files in a container.Command: docker run -it -v /etc/config:/config myimage Flags: -v mounts the host directory, -it allows interactive shell.
docker run -it -v /etc/config:/config myimage
Error message: Permission denied Why it happens: The user running the Docker command does not have permission to access the host directory.Fix: sudo docker run ...
Permission denied
sudo docker run ...
Error message: No such file or directory Why it happens: The host directory does not exist.Fix: mkdir /host/path
No such file or directory
Error message: Bind mount already exists Why it happens: The bind mount is already mounted.Fix: docker stop <container_id> and docker rm <container_id>
Bind mount already exists
Situation: You want to check if a directory is mounted in a container.Command: docker exec -it <container_id> ls /container/path Correct response: List of files and directories in the host directory.
Situation: You want to check if a file is accessible in a container.Command: docker exec -it <container_id> cat /container/path/file.txt Correct response: File contents.
docker exec -it <container_id> cat /container/path/file.txt
Situation: You want to check if a directory is writable in a container.Command: docker exec -it <container_id> touch /container/path/newfile.txt Correct response: File created.
docker exec -it <container_id> touch /container/path/newfile.txt
• The -v flag is used to mount a bind mount.• The format is -v /host/path:/container/path.• The host directory must exist before mounting.• The container directory must exist before mounting.• ⚠️ Be careful when using bind mounts, as they can expose sensitive data.• ⚠️ Use docker stop and docker rm to clean up containers.• ⚠️ Use sudo to run Docker commands with elevated privileges.• The docker exec command is used to execute a command in a running container.• The docker run command is used to create and start a new container.• ⚠️ Use docker version to check the Docker version.
-v /host/path:/container/path
docker stop
docker rm
sudo
docker exec
docker run
docker version
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.