【发布时间】:2016-01-15 17:41:27
【问题描述】:
我有一个 Angular 站点,我正尝试在 docker 容器中运行(现在只能通过 boot2docker)。
Dockerfile 如下所示:
FROM ubuntu:14.04
RUN sudo apt-get update
RUN sudo apt-get install -y npm
# Set in what directory commands will run
WORKDIR /home/app
# Put all our code inside that directory that lives in the container
ADD . /home/app
RUN sudo npm install && \
sudo npm install -g grunt-cli
#Need to do this for npm and bower
RUN ln -s /usr/bin/nodejs /usr/bin/node
# Install dependencies
RUN sudo npm install -g bower && \
sudo npm install -g grunt-cli && \
sudo npm install && \
bower install --config.interactive=false --allow-root
EXPOSE 9000
# The command to run our app when the container is run
ENTRYPOINT ["npm","start"]
当我运行 docker build -t web-app . 时,图像构建良好。
然后我运行以下命令来为容器加注星标
docker run --name my-web-app -p 9000:9000 -d web-app
如果我运行docker logs,我可以看到它正在工作......
> sb-admin@0.0.0 start /home/app
> grunt serve
Running "serve" task
Running "clean:server" (clean) task
Cleaning .tmp...OK
Running "concurrent:server" (concurrent) task
Running "copy:styles" (copy) task
Copied 3 files
Done, without errors.
Execution Time (2015-07-27 05:04:02 UTC)
loading tasks 2ms ▇▇▇▇▇▇▇▇▇ 18%
copy:styles 9ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 82%
Total 11ms
Running "autoprefixer:dist" (autoprefixer) task
File .tmp/styles/main.css created.
File .tmp/styles/sb-admin-2.css created.
File .tmp/styles/timeline.css created.
Running "connect:livereload" (connect) task
Started connect web server on http://localhost:9000
Running "watch" task
Waiting...
如果我手动运行npm start(不在容器中,只是在我的本地),则该站点在http://localhost:9000 可用,但是当我导航到从IP=$(boot2docker ip) 获得的IP 地址时,我收到连接被拒绝.
如果我通过 SSH 进入容器并运行以下任一命令,也会发生同样的情况:
IP=$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" my-web-app)
curl -X GET $IP:9000
我觉得我已经运行了数百个这样的容器并且可以正常访问它们,所以我不确定我做错了什么。
【问题讨论】:
-
我发现了这个问题,我会尽快发布。
标签: angularjs node.js docker boot2docker