docker - 为什么 Node 应用程序无法在 Docker Swarm 上运行?
问题描述
我有一个基本的节点应用程序,
const http=require('http');
http.createServer((req,res)=>{
res.writeHead(200,{'Content-Type': 'text/html'});
res.end('<h1>Hello World</h1>')
}).listen(3000);
console.log('Service Started on port 3000')
有一个 Dockerfile,
FROM node
RUN apt-get update -q && apt-get dist-upgrade -y && apt-get clean && apt-get autoclean
EXPOSE 3000
ENV APP_PATH /usr/share/app
WORKDIR $APP_PATH
USER node
COPY . $APP_PATH
CMD ["npm","start"]
我使用它创建了一个图像,sudo docker build -t prototype .
当我使用初始化一个 docker swarm 时sudo docker swarm init
,我得到了这个结果,
Error response from daemon: could not choose an IP address to advertise since this system has multiple addresses on interface enp3s0 (2405:201:8008:881f:a137:a31d:cb90:b885 and 2405:201:8008:881f:1925:6903:a2e2:249) - specify one with --advertise-addr
然后运行sudo docker swarm init --advertise-addr 2405:201:8008:881f:1925:6903:a2e2:249
,sudo docker service create -d --name node01 -p 3000:3000 prototype
然后sudo docker service ls
,我得到以下结果,
ID NAME MODE REPLICAS IMAGE PORTS
d7fu78estgkv node01 replicated 1/1 prototype:latest *:3000->3000/tcp
但是当我打开这个 url 时,http://localhost:3000/
什么都没有,浏览器继续加载。
解决方案
推荐阅读
- ruby-on-rails - 类中的 NoMethodError#new
- c# - Blazor 依赖注入与简单类
- vue.js - Vue.js 中关于动态元素 $off 的 EventBue 删除了所有重用的组件,而不是一个
- c++ - 数据包访问实践
- go - 由于找不到本地包,无法将 Go 应用程序部署到 GAE
- wordpress - 从 WP Bakery Single Image Block 上传突然失败
- c - Ecore_Job 内存泄漏的可能性?
- javascript - 使用正则表达式提取计量单位
- c# - 使用 IIS 运行一个简单的 ASP.NET Core 应用程序,给出一个空白页
- android - 圆形图像视图未显示