最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Running nuxt js application in Docker - Stack Overflow

programmeradmin0浏览0评论

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" ]

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?

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" ]

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?

Share Improve this question asked May 2, 2017 at 20:35 gajosgajos 9072 gold badges10 silver badges21 bronze badges 1
  • Visitors from the future, can take a look at this cookbook recipe for dockerizing your vue app – Anima-t3d Commented Apr 18, 2018 at 4:29
Add a comment  | 

1 Answer 1

Reset to default 18

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

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

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

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

发布评论

评论列表(0)

  1. 暂无评论