在Docker中运行nuxt js应用程序 [英] Running nuxt js application in Docker

查看:158
本文介绍了在Docker中运行nuxt js应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在docker容器中运行nuxt应用程序。为此,我创建了以下Dockerfile:

I'm trying to run nuxt application in docker container. In order to do so, I created the following Dockerfile:

FROM node:6.10.2

RUN mkdir -p /app

EXPOSE 3000

COPY . /app
WORKDIR /app
RUN npm install
RUN npm run build

CMD [ "npm", "start" ]

但是,当我构建映像并运行容器时( docker run -p 3000:3000< image- id> )在浏览器中按 localhost:3000 时,我什么也没得到。

However, when I build the image and run the container (docker run -p 3000:3000 <image-id>) I get nothing while hitting localhost:3000 in my browser. What could be the cause?

推荐答案

默认情况下,Docker容器中的应用程序接受 http上的网络流量://127.0.0.1:3000 。该接口不接受外部流量,因此也就不起作用了。为了使其工作,我们需要将nuxt应用程序的HOST环境变量设置为 0.0.0.0 (所有ip地址)。我们可以在Dockerfile中执行以下操作:

The application inside Docker container by default is accepting network traffic onhttp://127.0.0.1:3000. This interface does not accept external traffic so no wonder that it does not work. In order to make it work we need to set HOST environmental variable for nuxt app to 0.0.0.0 (all ip addresses). We can do this either in Dockerfile, like this:

FROM node:6.10.2

ENV HOST 0.0.0.0

# rest of the file

或打包。脚本的启动命令中的json:

or in package.json in the script's "start" command:

scripts:{ start: HOST = 0.0.0.0 nuxt start .. 。}

或其他任何使nuxt应用程序仅在容器内的本地主机上进行侦听的方法。

Or any other way that will make the nuxt application to listen elsewhere than on localhost inside container only.

这篇关于在Docker中运行nuxt js应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆