Question
I would like to see the vue-cli welcome page in chrome, running from a Docker Container on my Mac. I am struggling to set up the proper configuration for this to work. What am I missing? Here is what I have tried.
Steps
Installed
- Docker for Mac - 17.12.0-ce
- npm 5.6.0
- vue-cli 2.9.3
Command Line
$ vue init webpack docvue
$ cd docvue
$ npm install
Files
After running the commands above, I now have the vue example project ready to build with webpack.
$ ls
README.md config node_modules package.json static
build index.html package-lock.json src
Within /docvue/
I can npm run dev
, and I see:
> docvue@1.0.0 dev /Users/dchaddportwine/Startup/docvue
> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js
95% emitting
DONE Compiled successfully in 4695ms 12:17:04 PM
Your application is running here: http://localhost:8080
And in Chrome at http://localhost:8080/#/
I see the Vue Welcome page.
Build the Docker Image
Now it's time to build the Docker Image using this Dockerfile:
# base image
FROM node:8.10.0-alpine
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
COPY package*.json ./
RUN npm install
# Bundle app source
COPY . .
EXPOSE 8080
CMD [ "npm", "start" ]
Command Line
$ docker build -t cportwine/docvue .
Successfully built 61bc30c3695b
Successfully tagged cportwine/docvue:latest
And now it's time to run the Docker image in a container:
$ docker run --rm -d cportwine/docvue
34ba43323723c046869775f6f00e11b895c4124680784ebcaff7f711c99fc82d
And check the logs:
$ docker logs 34ba43323723c046869775f6f00e11b895c4124680784ebcaff7f711c99fc82d
> docvue@1.0.0 start /usr/src/app
> npm run dev
> docvue@1.0.0 dev /usr/src/app
> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js
78% advanced chunk op DONE Compiled successfully in 4383ms16:56:56
Your application is running here: http://localhost:8080
Problem
In chrome, at http://localhost:8080/#/
I get "This site can't be reached".
The running container looks like this:
$docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
34ba43323723 cportwine/docvue "npm start" 7 minutes ago Up 7 minutes 8080/tcp agitated_payne
What if
What if I run the Docker container using the publish option:
$ docker run --rm -p3000:8080 -d cportwine/docvue
2f9dd0bf1caa11d96352012913eb58c7883e1db95a7ceb72e2e264184c368261
And check the logs:
$ docker logs 2f9dd0bf1caa11d96352012913eb58c7883e1db95a7ceb72e2e264184c368261
> docvue@1.0.0 start /usr/src/app
> npm run dev
> docvue@1.0.0 dev /usr/src/app
> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js
78% advanced chunk op DONE Compiled successfully in 4438ms17:08:09
Your application is running here: http://localhost:8080
Problem 2
Wait, is this better?
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2f9dd0bf1caa cportwine/docvue "npm start" 8 minutes ago Up 8 minutes 0.0.0.0:3000->8080/tcp zen_liskov
In chrome, at http://localhost:3000/#/
Now I get "This page isn’t working - localhost didn’t send any data."
But I do not see the Vue Welcome page.