I have a problem when building docker for vuejs app
I have a vuejs app and now I want to build a docker image for it
This is my Dockerfile
FROM node:7.7.2-alpine
WORKDIR /usr/app
COPY package.json .
RUN npm install --quiet
COPY . .
EXPOSE 8080
And This is my docker-compose.yml file
version: '2'
services:
web:
build: .
command: npm run dev
volumes:
- .:/usr/app
- /usr/app/node_modules
ports:
- "8080:8080"
When I run command docker-compose up. I get this result:
But when I access the url http://localhost:8080
on my host. I get this:
I don't know exactly what happened. Please help me to fix this problem.
Thank you so much.
These are my source code folders:
Build a Docker Vue JS Image using Dockerfile Start the Container from the Image we have created Validate the web application Running inside Container Securing Vue JS Application using NGINX (Optional) Create a Dockerfile Build a Docker Vue JS Image using Dockerfile
One way is to dockerize the Vue.js app with nodejs backend and create a docker image so that we can deploy that image any time or sometimes several times a day. In this post, we look at the example project and see the step by step guide on how we can dockerizing the Vue.js app with nodejs as a server.
Secondly you are using CMD ["node"] which does not start your vue application, so there is no job running and docker is shutting down. For vue applicaton you normally want to build the app with static assets and then run a simple http server to serve the static content.
- Check out the first part of the Vue-Docker series. - Or if you're TL: DR - take me to the code. Now that we have Docker installed and scaffolded our project, we can start developing. Let's begin by adding the following to the Dev.Dockerfile:
By default npm run dev
binds to localhost only.
Add --host 0.0.0.0
to your webpack-dev-server
line in package.json
:
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",
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With