swdev
swdev

Reputation: 5157

Dockerfile in Windows 10 Linux Subsystem can't find file in current directory

I have a Dockerfile with this last line:

CMD ["./watch.sh"]

Which just running an npm run watch. In Linux, all work fine. But in Windows 10 Subsytem for Linux (WSL), docker will throw an error saying it can't find the file. In another Dockerfile that runs python <SOMEFILE.PY> it also says it can't find the file.

I have already set these in /etc/wsl.conf:

[automount]
root = /
options = "metadata"

I run docker in my username process, and had already put my name in docker group. So, I don't run it as sudo. The files permission has also in my account.

EDITED: I just realize that, it seems like I need to run docker client as sudo. From within Bash WSL, it seems like it can't find docker engine that reside in Windows, access via tcp://localhost:2375

$ sudo usermod -aG docker root
$ sudo docker build -t build-minimal .
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

When I run docker without sudo, it works.

Upvotes: 1

Views: 1541

Answers (1)

swdev
swdev

Reputation: 5157

Found it! The answer is file permissions.

My intention to use WSL is to have fully compliant Linux environment, but still able to work using Windows. Hence, file sharing between Linux and Windows must be done correctly.

My mistakes previously was simply symlink from Linux to my Windows file (Python Flask app that is). That is bad, because file permission will not be store/read correctly.

Solution:

  • Symlink to the directory of your code/data reside in Windows folder
  • If it is a git repository, do a git clone from within WSL box
  • This will make file permissions retained correctly and you still be able accessing them from within both WSL/Windows flawlessly

Upvotes: 3

Related Questions