[英]Can't dockerize Nuxt.js application
I have simple Nuxt.js application and I want to dockerize it.我有简单的 Nuxt.js 应用程序,我想对它进行 docker 化。 Here is the script:
这是脚本:
FROM node
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 8010
CMD [ "npm", "start" ]
When I build it and run container it seems to work and I can see something like this:当我构建它并运行容器时,它似乎可以工作,我可以看到如下内容:
Entrypoint app = server.js server.js.map
READY Server listening on http://127.0.0.1:8010
But when I'm trying to see it in browser I get just error - This page isn't working
.但是当我试图在浏览器中查看它时,我得到的只是错误 -
This page isn't working
。
So, in general, how can I dockerize my Nuxt.js
application and make it work on my machine?所以,一般来说,我怎样才能对我的
Nuxt.js
应用程序进行 dockerize 并使其在我的机器上运行?
Your app binds to 127.0.0.1 which means that it'll only accept connections from inside the container.您的应用绑定到 127.0.0.1,这意味着它只会接受来自容器内部的连接。 By reading the docs, it seems you can set the HOST environment variable to the binding address you want.
通过阅读文档,您似乎可以将 HOST 环境变量设置为您想要的绑定地址。 Try this, which sets it to 0.0.0.0 which means that the app accepts connections from everywhere
试试这个,将它设置为 0.0.0.0 这意味着应用程序接受来自任何地方的连接
FROM node
ENV HOST=0.0.0.0
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 8010
CMD [ "npm", "start" ]
When running it, you should see READY Server listening on http://0.0.0.0:8010
rather than READY Server listening on http://127.0.0.1:8010
运行它时,您应该看到
READY Server listening on http://0.0.0.0:8010
而不是READY Server listening on http://127.0.0.1:8010
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.