使用 Docker 容器化 Quasar 專案

做法

新增 docker-compose.yaml 檔:

1
2
3
4
5
6
7
8
version: "3"

services:
app:
container_name: quasar
build: .
ports:
- "3000:3000"

新增 Dockerfile 檔:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# build stage
FROM node:alpine as builder

WORKDIR /app

COPY . .

RUN yarn global add @quasar/cli
RUN yarn install
RUN quasar build -m ssr

# final stage
FROM node:alpine

WORKDIR /root

COPY --from=builder /app/dist/ssr .

RUN yarn install

CMD [ "yarn", "start" ]

新增 .dockerignore 檔:

1
2
3
4
5
6
7
.git
.gitignore
Dockerfile
docker-compose.yaml
node_modules
dist
.env.*.js

編譯並啟動容器:

1
docker-compose up -d --build

瀏覽網頁

前往 http://127.0.0.1:3000 瀏覽。