8

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?

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Absolutely right, I didn't find your answer since I googled wrong - but had the same problem. It's also in the nuxt FAQ docs. Setting HOST=0.0.0.0 is key.
Using Paketo.io / Cloud Native Buildpacks would free you from the need to write your own Dockerfile - then you need to pass the HOST=0.0.0.0 as --env variable to the docker run command (see this answer).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.