Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Docker-在Docker容器(Windows)中正确装载主机目录_Node.js_Docker - Fatal编程技术网

Node.js Docker-在Docker容器(Windows)中正确装载主机目录

Node.js Docker-在Docker容器(Windows)中正确装载主机目录,node.js,docker,Node.js,Docker,我在将机器上的目录装入Docker容器时遇到一些问题。我想挂载一个目录,其中包含运行节点服务器所需的文件。到目前为止,我已成功使用下面的Dockerfile在浏览器中运行和访问我的服务器: # Use an ubuntu base image FROM ubuntu:14.04 # Install Node.js and npm (this will install the latest version for ubuntu) RUN apt-get update RUN apt-get

我在将机器上的目录装入Docker容器时遇到一些问题。我想挂载一个目录,其中包含运行节点服务器所需的文件。到目前为止,我已成功使用下面的Dockerfile在浏览器中运行和访问我的服务器:

# Use an ubuntu base image
FROM    ubuntu:14.04

# Install Node.js and npm (this will install the latest version for ubuntu)
RUN apt-get update
RUN apt-get -y install curl
RUN curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
RUN apt-get -y install nodejs
RUN apt-get -y install git

# Bundle app source (note: all of my configuration files/folders are in the current directory along with the Dockerfile)

COPY . /src

Install app dependencies

#WORKDIR /src

RUN npm install
RUN npm install -g bower
RUN bower install --allow-root
RUN npm install -g grunt
RUN npm install -g grunt-cli

#What port to expose?

EXPOSE  1234

#Run grunt on container start

CMD grunt
这些命令是:

docker build -t test/test .

docker run -p 1234:1234 -d test/test
但是,我认为我希望配置文件和其他东西能够持久化,并想通过将目录(包含文件和Dockerfile)作为卷装载来实现这一点。我在StackOverflow上使用了其他解决方案来获取此命令:

docker run -p 1234:1234 -v //c/Users/username/directory:/src -d test/test
我的节点服务器似乎启动得很好(日志中没有错误),但这样做需要更长的时间,当我尝试在浏览器中访问我的网页时,我只得到一个空白页面

我做错什么了吗


编辑:我已经让我的服务器运行了——在我的配置中似乎出现了一个奇怪的错误。但是,当我从主机装载卷时,服务器启动仍然需要很长时间(大约一到两分钟)。有人知道这是为什么吗?

如果我没记错的话,boot2docker使用VirtualBox的共享文件夹将主机目录映射到boot2docker VM,然后再映射到Docker容器。VirtualBox共享文件夹不可用。我不确定你是否能在Windows上对此做些什么……啊,我明白了。这是有道理的——我将在Ubuntu上测试我的服务器,看看这是否会有所不同。谢谢