Hey everyone! I'm pretty new to Docker and started my journey a few weeks ago while setting up a home media server using the *arr application stack. I'm currently using Docker Desktop on Windows with WSL 2, and I ran into a bit of a snag with mounting .env files. Sometimes, developers provide separate env files to keep things organized, but I'm having trouble getting this to work with my Windows setup.
For instance, I'm trying to set up a komodo container with Portainer, and the standard way to do this in a Docker Compose file is to include the 'env_file' directive like so:
``nenv_file: ./compose.env``,
and I attempted to bind mount the file from my Windows path like this:
``volumes:
- C:DockerVolumesV-Komodoenv:./compose.env``
However, I'm getting an error saying "no such file or directory." I've also tried mounting a folder instead, but I'm still hitting the same issue. Any insights on how to resolve this?
3 Answers
I just wanted to chime in that when you use 'C:DockerVolumesV-Komodoenv:./compose.env', the './' indicates a relative path inside the container. Try changing that to an absolute path inside the container instead. Also, Windows can be picky about file extensions – make sure the file isn’t named something like env.txt with the extension hidden.
You might be dealing with two layers of filesystem abstraction here. Remember, Docker Desktop runs inside a WSL instance, and the paths need to translate correctly. Portainer runs in a container, too, so you need to check that the paths you're using inside it are accessible. It's likely that WSL isn't mapping properly to what Portainer can see. Can you confirm if other volumes are working fine?
It sounds like you're running into a common issue with path handling on Windows. When you use the 'env_file' option in Docker Compose, you actually don't need to mount the env file directly into the container. Simply having the correct Windows path in your 'env_file' declaration should suffice. Just make sure it's formatted correctly for WSL to recognize it!
That’s what I was thinking! It's cleaner that way, right? Just ensure the env file exists at the specified path, and Docker should pick it up without needing to be mounted.

Yeah, I have other bind mounts set up, and they work perfectly, so it's frustrating that just this one isn't cooperating.