Skip to content

Commit 83cba2e

Browse files
committed
1 parent 70d3799 commit 83cba2e

File tree

5 files changed

+77
-15
lines changed

5 files changed

+77
-15
lines changed

Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM nginx
2+
3+
COPY dist/ /usr/share/nginx/html/
4+
5+
COPY nginx/default.conf /etc/nginx/conf.d/default.conf

README.md

+24-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
# vue-docker-nginx
22

3-
## Project setup
4-
```
5-
npm install
6-
```
3+
> A Vue.js project
74
8-
### Compiles and hot-reloads for development
9-
```
10-
npm run serve
11-
```
5+
## 将vue项目配合nginx在docker中打包运行
126

13-
### Compiles and minifies for production
14-
```
7+
## Build Setup
8+
9+
``` bash
10+
# 打开docker
11+
12+
#下载docker中下载nginx
13+
docker pull nginx
14+
15+
# 安装vue项目中的npm依赖
16+
npm install
17+
18+
# 本地打包,生成dist文件
1519
npm run build
20+
21+
# docker创建镜像
22+
docker build -t vue-docker-nginx .
23+
24+
# 本地localhost:4000端口监听容器80容器启动docker
25+
docker run -p 4000:8080 -d vue-docker-nginx
26+
1627
```
1728

18-
### Customize configuration
19-
See [Configuration Reference](https://cli.vuejs.org/config/).
29+
现在就可以在本机游览器查看在docker中启动的项目了。http://localhost:4000/
30+
31+
![Image](https://raw.githubusercontent.com/Mary5haw/vue-docker-nginx/master/img/img1.png)

img/img1.png

45.3 KB
Loading

nginx/default.conf

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
server {
2+
3+
listen 8080;
4+
5+
server_name localhost;
6+
7+
8+
9+
#charset koi8-r;
10+
11+
access_log /var/log/nginx/host.access.log main;
12+
13+
error_log /var/log/nginx/error.log error;
14+
15+
16+
17+
location / {
18+
19+
root /usr/share/nginx/html;
20+
21+
index index.html index.htm;
22+
23+
}
24+
25+
26+
27+
#error_page 404 /404.html;
28+
29+
30+
31+
# redirect server error pages to the static page /50x.html
32+
33+
#
34+
35+
error_page 500 502 503 504 /50x.html;
36+
37+
location = /50x.html {
38+
39+
root /usr/share/nginx/html;
40+
41+
}
42+
43+
}

src/App.vue

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<template>
22
<div id="app">
3-
<img alt="Vue logo" src="./assets/logo.png">
4-
<HelloWorld msg="Welcome to Your Vue.js App"/>
3+
<h1>Congratulations on your!<br />Successful run vue in docker!</h1>
4+
<img alt="Vue logo"
5+
src="./assets/logo.png">
6+
<HelloWorld msg="Welcome to Your Vue.js App" />
57
</div>
68
</template>
79

@@ -18,7 +20,7 @@ export default {
1820

1921
<style>
2022
#app {
21-
font-family: 'Avenir', Helvetica, Arial, sans-serif;
23+
font-family: "Avenir", Helvetica, Arial, sans-serif;
2224
-webkit-font-smoothing: antialiased;
2325
-moz-osx-font-smoothing: grayscale;
2426
text-align: center;

0 commit comments

Comments
 (0)