Docker Creates a Folder Instead of Mounting a File in Window
In most cases, the problem occurs because the source file does not exist at the specified host path, the volume path is incorrect, or Docker cannot access the expected file. When Docker uses the -v or –volume option with a missing source path, it can create a directory instead.
Fortunately, you can fix this problem by checking the file path, using the correct volume mounting syntax, and verifying your Docker Desktop configuration.
In this guide, we will explain why Docker creates a folder instead of mounting a file in Windows and walk you through several ways to resolve the issue.
Docker Creates a Folder Instead of Mounting a File in Windows

Before trying the fixes, it is important to understand why Docker behaves this way.
When you mount a file from Windows into a Docker container, Docker expects the source path to point to an existing file. If the path is incorrect or the file does not exist, Docker’s -v or –volume syntax can create a directory at the source location.
For example, consider this command:
docker run -d –name my-nginx -v C:\docker\nginx.conf:/etc/nginx/nginx.conf nginx
If C:\docker\nginx.conf does not exist as a file, Docker may create a directory with that name instead of mounting the expected configuration file.
Let’s go through the troubleshooting methods to fix this issue.
1: Check Whether the Source File Exists
The first thing you should do is verify that the file you want to mount actually exists on your Windows computer.
Docker cannot mount a file that is missing from the specified source location. If you provide an incorrect path, Docker may interpret it as a directory when using the -v syntax.
Open File Explorer and navigate to the folder containing your configuration file. Check whether the file exists and whether its extension is correct.
For example, if you want to mount nginx.conf, make sure the actual file is available at:
C:\docker\nginx.conf
You can also verify the file using PowerShell. Open PowerShell and execute:
Test-Path “C:\docker\nginx.conf” -PathType Leaf
If the command returns True, the specified path points to an existing file.
If it returns False, check the filename, directory location, and file extension.
You can also list the contents of the directory using:
Get-ChildItem “C:\docker”
Make sure Windows has not accidentally saved the file as nginx.conf.txt. This can happen when file extensions are hidden in File Explorer.
Once you confirm that the source file exists, try running your Docker command again.
2: Use the Correct Docker Volume Mount Syntax
Incorrect volume syntax is another common reason Docker creates a directory instead of mounting a file.
Docker supports different ways to mount files and folders. When using the -v option, you must provide the correct host path and container path, separated by a colon.
For example:
docker run -d –name my-nginx -v “C:\docker\nginx.conf:/etc/nginx/nginx.conf” nginx
Here, C:\docker\nginx.conf represents the Windows source file, while /etc/nginx/nginx.conf represents the destination file inside the container.
Make sure both paths are correct. The source must point to an existing Windows file, and the destination should be the location where you want that file to appear inside the container.
You can also use Docker’s –mount option, which provides a more explicit way to define mounts.
For example:
docker run -d –name my-nginx –mount “type=bind,source=C:\docker\nginx.conf,target=/etc/nginx/nginx.conf” nginx
The –mount option is often easier to troubleshoot because it clearly separates the mount type, source, and target.
Unlike the -v option, –mount normally reports an error when the source path does not exist instead of automatically creating a directory.
This makes it a useful option when you specifically want to mount an existing file.
3: Use the Correct File Path in Windows
Windows and Linux use different path formats. Windows generally uses backslashes (\), while Linux containers use forward slashes (/).
This difference can sometimes cause problems when writing Docker volume commands.
For example, you might use:
C:\Users\Admin\docker\config.json
as your Windows source path and:
/app/config.json
as your container destination.
A correctly formatted command would look like this:
docker run -d –name my-app –mount “type=bind,source=C:\Users\Admin\docker\config.json,target=/app/config.json” my-image
Replace the Windows username, directory, filename, and image name with your actual values.
If you are using a project directory, you can also use PowerShell to obtain its absolute path:
(Get-Location).Path
This helps you avoid mistakes when working with relative paths.
Important: If you are using relative paths, make sure they resolve to the directory you expect. Docker commands executed from a different working directory may point to the wrong location.
4: Use PowerShell to Verify the Mount
If Docker still creates a folder, verify the source and destination paths before running the container again.
Open PowerShell and execute:
$Source = “C:\docker\nginx.conf”
Test-Path $Source -PathType Leaf
If the result is True, the file exists.
Next, inspect its properties:
Get-Item $Source
This command displays the file information, including its name, size, and type.
Now run your Docker container using the –mount option:
docker run -d –name test-container –mount “type=bind,source=C:\docker\nginx.conf,target=/tmp/nginx.conf,readonly” nginx
The readonly option prevents the container from modifying the mounted file.
To verify the mount, execute:
docker exec test-container ls -l /tmp/nginx.conf
The output should show nginx.conf as a regular file rather than a directory.
You can also inspect the mount configuration:
docker inspect test-container
Look under the Mounts section to check the source, destination, and mount type.
5: Check Docker Desktop File Sharing Permissions
Sometimes the source file exists, and your Docker command is correct, but Docker Desktop cannot access the Windows directory.
This can happen because of file-sharing permissions or Docker Desktop configuration.
To check this, open Docker Desktop on your Windows computer.
Navigate to Settings and look for the file-sharing or resource-access settings available in your Docker Desktop version. Depending on your backend and version, Windows file access may be managed differently.
If you are using the WSL 2 backend, make sure your Windows directory is accessible from the WSL environment.
For example, you can check a Windows C drive path from WSL using:
ls /mnt/c/docker
If you cannot access the directory, check your WSL configuration and Docker Desktop integration settings.
Also, make sure Docker Desktop is running properly and that the account running Docker has permission to access the source file.
After making any necessary configuration changes, restart Docker Desktop and try the bind mount again.
6: Remove the Incorrectly Created Folder
If Docker has already created a directory with the same name as your intended configuration file, you may need to remove it before trying again.
First, check whether the path is a directory:
Get-Item “C:\docker\nginx.conf”
If the output identifies it as a directory, make sure it does not contain any important files.
To remove an empty directory, execute:
Remove-Item “C:\docker\nginx.conf”
If it contains files, inspect them before deciding whether to remove the directory and its contents.
Next, create the actual configuration file. You can use Notepad:
notepad “C:\docker\nginx.conf”
Add your configuration, save the file, and close Notepad.
Now verify that it exists as a file:
Test-Path “C:\docker\nginx.conf” -PathType Leaf
Once the result returns True, rerun your Docker bind mount command.
7: Check Your Docker Compose Configuration
If you are using Docker Compose instead of the regular docker run command, check the volume configuration in your compose.yaml or docker-compose.yml file.
A common mistake is specifying an incorrect host path.
For example, your configuration might look like this:
services:
nginx:
image: nginx
volumes:
– ./nginx.conf:/etc/nginx/nginx.conf
Here, ./nginx.conf refers to a file relative to the Compose project’s working directory.
If the file does not exist in that location, Docker may create a directory when using short volume syntax.
A clearer alternative is the long mount syntax:
services:
nginx:
image: nginx
volumes:
– type: bind
source: ./nginx.conf
target: /etc/nginx/nginx.conf
read_only: true
The long syntax makes the source and target easier to identify.
Run the following command to start your application:
docker compose up -d
If the source file is missing, the long syntax generally produces a clearer error rather than silently creating a directory.
Make sure nginx.conf is located in the same directory as your Compose file, unless you have specified another valid path.
FAQs
1. Why does Docker create a directory instead of mounting a file?
Docker may create a directory when the source file does not exist at the specified host path, and you use the -v or –volume syntax. Check the filename, extension, and absolute path before creating the container.
2. How do I mount a single file in Docker on Windows?
You can use the –mount option:
docker run –mount “type=bind,source=C:\docker\config.txt,target=/app/config.txt” my-image
Make sure the source file already exists on your Windows computer.
3. Is Docker’s -v option different from –mount?
Yes. Both options support bind mounts, but their behavior differs when the source path does not exist. The -v option can create a missing source directory, while –mount generally reports an error if the source path is missing.
4. Can Docker mount a Windows file into a Linux container?
Yes. Docker Desktop supports mounting Windows host files into Linux containers. You need to provide a valid Windows source path and a valid destination path inside the container.
5. How do I check whether Docker successfully mounted a file?
You can inspect the container using:
docker inspect my-container
You can also check the destination inside the container:
docker exec my-container ls -l /app/config.txt
A successful file mount should show the destination as a regular file.
6. Should I use absolute or relative paths for Docker volumes?
Absolute paths are generally easier to troubleshoot because they clearly identify the source file’s location. Relative paths are also supported, particularly with Docker Compose, but they depend on the working directory and project configuration.
Summary
Docker creating a folder instead of mounting a file in Windows is usually related to an incorrect source path, a missing file, or an improperly configured bind mount.
Start by checking whether the source file exists and confirming its extension. Next, verify your Docker volume syntax and consider using the –mount option instead of -v. If the issue continues, check Docker Desktop permissions, WSL integration, and your Docker Compose configuration.
For most situations, this command is a good starting point:
docker run -d –name my-container –mount “type=bind,source=C:\docker\config.txt,target=/app/config.txt” my-image
Remember to replace the paths and image name with your actual values.
