[英]babel-watch doesn't work from docker container on windows host when mounting a host directory as a network share
I'm using docker on Windows and my src directory is mounted as a network share inside the docker container (as opposed to COPY). 我在Windows上使用docker,我的src目录作为网络共享安装在docker容器内 (而不是COPY)。 So /var/app/server
inside the docker is actually a network share whose actual location on my host is C:\\...project\\server
. 因此docker中的/var/app/server
实际上是一个网络共享,其在我的主机上的实际位置是C:\\...project\\server
。 [sidenote, I'm not familiar with how docker works on linux, like does it still use network share for mount on linux as well? [旁注,我对docker在linux上的工作方式不熟悉,就像它还在使用网络共享在linux上挂载一样吗? because if not then this might just be windows issue] 因为如果没有,那么这可能只是Windows问题]
I'm using babel-watch which uses mkfifo
, and since it's running inside the docker container (VM) mkfifo can't create a file-pipe in that network shared directory. 我正在使用使用mkfifo
babel-watch,并且由于它在docker容器(VM)中运行,因此mkfifo无法在该网络共享目录中创建文件管道。 [sidenote: babel-watch actually does works on windows outside docker with cygwin which has a mkfifo.exe utility] [旁注:babel-watch实际上可以通过具有mkfifo.exe实用程序的cygwin在docker外部的Windows上运行。
server_1 | mkfifo: cannot create fifo `/var/app/server/116521-16-pz2v9g.ma216skyb9': Operation not permitted
server_1 | Unable to create named pipe with mkfifo. Are you on linux/OSX?
Is there any workaround to this? 有什么解决方法吗?
I tried editing babel-watch source to have mkfifo create a file in /var/app
or /var
instead (where it would still be inside the realm of the docker container) and while this way mkfifo
actually works, the file changes aren't seen by babel-watch. 我尝试编辑babel-watch源,以使mkfifo在/var/app
或/var
创建文件(该文件仍将在docker容器的范围内),并且虽然mkfifo
实际上有效,但文件更改不会通天塔看。 I guess fundamentally the file change info isn't able to propagate pass the network share barrier - /var/app/server
(the mount point) to /var/app
(real directory inside docker). 我想从根本上说文件更改信息无法通过网络共享屏障- /var/app/server
(挂载点)传播到/var/app
(泊坞窗内的真实目录)。
mkfifo
requires Linux/OSX environment, while /var/app/server
was mounted from Windows. mkfifo
需要Linux / OSX环境,而/var/app/server
是从Windows挂载的。 So it does not works. 因此它不起作用。 So you should ADD
or COPY
instead of mount volume 因此,您应该ADD
或COPY
而不是挂载卷
I recently ran into this issue and did a little digging. 我最近遇到了这个问题,做了一些挖掘。
If you look into the babel-watch source (at the time of writing) you'll see it tried to create the named pipe in the OS's temporary directory. 如果查看babel-watch源文件 (在撰写本文时),您会看到它尝试在OS的临时目录中创建命名管道。
function generateTempFilename() {
const now = new Date();
return path.join(os.tmpdir(), [
now.getYear(), now.getMonth(), now.getDate(),
'-',
process.pid,
'-',
(Math.random() * 0x100000000 + 1).toString(36),
].join(''));
}
In our docker containers $TMPDIR
was not set which results in the named pipe being created in the current working directory. 在我们的Docker容器中,未设置$TMPDIR
,这导致在当前工作目录中创建命名管道。 Setting it changes this: 对其进行设置将更改:
TEMP_DIR=/tmp babel-watch index.js
This meant that the mkfifo
call wasn't targeting the windows file system. 这意味着mkfifo
调用未针对Windows文件系统。 This however didn't solve the problem of changes not being picked on the Windows file system. 但是,这不能解决Windows文件系统上未选择更改的问题。 To detect changes you can use the polling flag --use-polling
. 要检测更改,可以使用轮询标志--use-polling
。 This makes the command: 这使命令:
TEMP_DIR=/tmp babel-watch --use-polling index.js
Using these two together allowed us to use babel-watch from a docker container in Docker for Windows. 将这两者结合使用,使我们能够从Windows版Docker中的Docker容器中使用babel-watch。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.