Bind Mounts and tmpfs Mounts
Learn about bind mounts for accessing host files and tmpfs mounts for ephemeral data storage.
Bind Mounts and tmpfs Mounts is a free Docker & DevOps Fundamentals lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Docker & DevOps Fundamentals learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Data Storage Beyond Volumes
In previous lessons, we learned about Docker volumes for persistent data storage. But what if you need to share files directly from your host machine or store temporary data that doesn't need to persist?
This lesson introduces two more ways to manage data: bind mounts and tmpfs mounts. They offer flexibility for different use cases.

What are Bind Mounts?
A bind mount allows you to mount a file or directory from the host machine into a container. This creates a direct link, so changes made on either side are immediately reflected on the other.
- Host Path: The location on your computer.
- Container Path: The location inside the container.
- Ideal for development, sharing configuration, or accessing host files.
Bind Mounts in Action
Let's see a bind mount in action. This command mounts your current directory (represented by $(pwd) on Linux/macOS or %cd% on Windows CMD) into the container's /app directory.
Note: Before running, create a file named hello.txt in your current directory with some text like "Hello from host!".
docker run --rm -it \
-v "$(pwd):/app" \
alpine:latest sh -c "ls /app && cat /app/hello.txt"Read-Only Bind Mounts
Sometimes you want to share data from the host but prevent the container from making changes. This is where read-only bind mounts come in handy.
You can specify :ro at the end of the mount path or use the --mount flag with readonly to achieve this.
docker run --rm -it \
-v "$(pwd):/app:ro" \
alpine:latest sh -c "touch /app/new_file.txt || echo 'Permission denied!'"Understanding Read-Only Output
When you ran the previous command, you should have seen a "Permission denied!" message. This confirms that the container was unable to create a new file in the /app directory because it was mounted as read-only.
This is a great security feature to protect your host files from accidental or malicious changes by a container.
What are tmpfs Mounts?
A tmpfs mount is a temporary file system stored entirely in the host's memory (RAM). This means data written to a tmpfs mount is not persistent.
- Data is lost when the container stops.
- Faster I/O compared to disk-based storage.
- Good for sensitive data or temporary files.
tmpfs Mounts in Action
Let's create a container with a tmpfs mount. We'll write a file to it, then exit the container. When you run a new container, the file will be gone.
The --tmpfs flag specifies the mount point inside the container.
docker run --rm -it \
--tmpfs /app/temp_data \
alpine:latest sh -c "echo 'Ephemeral data' > /app/temp_data/my_temp_file.txt && ls /app/temp_data"Verifying tmpfs Ephemeral Nature
After running the last command, you saw my_temp_file.txt listed. Now, run this command to start a *new* container with the *same* tmpfs mount configuration.
You'll notice that my_temp_file.txt is no longer there. This confirms that tmpfs data is indeed temporary and specific to the container's lifecycle.
docker run --rm -it \
--tmpfs /app/temp_data \
alpine:latest ls /app/temp_dataBind Mounts vs. tmpfs Mounts
When should you use each?
- Bind Mounts: For sharing host files (e.g., config, source code) with containers, ensuring persistence and direct host access.
- tmpfs Mounts: For temporary, non-persistent data that needs high performance or shouldn't survive container restarts (e.g., caches, sensitive runtime data).
They both complement Docker volumes, offering a full range of data management options.
Quick Check: Mount Types
Which of the following statements are true about bind mounts and tmpfs mounts?
Recap: Data Management Tools
Fantastic work! You've expanded your Docker data management toolkit.
- Bind mounts link host files/directories to containers, great for development and config sharing.
- tmpfs mounts provide temporary, in-memory storage, perfect for non-persistent or sensitive data.
Understanding these options helps you choose the right storage solution for your containerized applications.
Frequently asked questions
Is the “Bind Mounts and tmpfs Mounts” lesson free?
Yes — the full text of “Bind Mounts and tmpfs Mounts” is free to read here on the web, and the Docker & DevOps Fundamentals course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Docker & DevOps Fundamentals course, upgrade to CoddyKit PRO.
What will I learn in “Bind Mounts and tmpfs Mounts”?
Learn about bind mounts for accessing host files and tmpfs mounts for ephemeral data storage. You practise Docker & DevOps Fundamentals with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Docker & DevOps Fundamentals?
No prior experience is required. Docker & DevOps Fundamentals on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Bind Mounts and tmpfs Mounts” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Docker & DevOps Fundamentals lesson?
Yes. Every Docker & DevOps Fundamentals lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Container Networking Basics
- Docker Volumes for Persistence
- Bind Mounts and tmpfs Mounts
- Custom Bridge Networks and Service Discovery