How to Mount a Local Folder into a Docker Container

Purpose

Bind-mount a local folder into a Docker container, enabling persistent storage and easy sharing of files between host and container.


1. Create the Local Folder

Create a folder on the host that you want to share:

mkdir -p ~/docker-data/myapp

2. Set Correct Permissions

Ensure the folder is accessible by Docker containers:

chmod 755 ~/docker-data/myapp

(Adjust permissions based on your security requirements.)


3. Run a Container with the Folder Mounted

Use the -v flag in Docker:

docker run -d \
  --name my-container \
  -v ~/docker-data/myapp:/app/data \
  my-docker-image

4. Verify the Mount

Inside the container, the folder should appear:

docker exec -it my-container ls /app/data

If you create files inside /app/data, they will appear inside your host folder too.


✅ Summary


🛠️ Useful Commands


Revision #1
Created 2025-04-27 02:37:28 UTC by joliveira
Updated 2025-04-27 02:37:48 UTC by joliveira