How to Containerize a Vue.js app? How to Containerize a Vue.js app? node.js node.js

How to Containerize a Vue.js app?


In a default vue-cli setup, npm start (the command you are using) runs npm run dev.

And, again, by default, npm run dev binds to localhost only.

Add --host 0.0.0.0 to your webpack-dev-server line in package.json so you can access it from outside the docker container:

From something like:

  "scripts": {    "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",

To something like (add --host 0.0.0.0):

    "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js --host 0.0.0.0",

Note: I'm assuming, because you used CMD ["npm", "start"], you are creating a container for development or debugging purposes. If you are targeting production, you should really consider generating the bundle (npm run build) and serving the generated files directly on a HTTP server like nginx (which could be created in a docker as well).