Docker uses a process known as mounting to allow files and folders on the host to be accessible from within a Docker container. There are two types of mounts that can be created: bind mounts and volume mounts.
1. Bind mounts: These can be created anywhere on the host system. They may even be important system folders or files. Docker will not manage the lifespan of these.
1. Volume mounts: These are managed by Docker. They can be created in a specific location on the host system or in Docker’s storage directory. Docker manages the lifespan of these, meaning it will clean up after them when they are no longer needed.
To share folders between a Docker host and a Docker container, use the -v flag that stands for —volume. The general syntax is as follows:
```
docker run -v /path/on/host:/path/in/container -t imagename
```
The folders or files specified will be mounted into the container at the specified location.
Example :
```
docker run -v /home/user/folder:/app -t my_image
```
This example will mount the host directory, /home/user/folder, into the container at /app. Any changes made to the directory /app inside the Docker container will be reflected on the host system in the directory, /home/user/folder.
It is important to remember that Docker runs as the root user (unless told otherwise), so there may be permissions issues with creating and modifying files.
Refer to Docker’s documentation on volumes for more information.