-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNoteScriptDay1.txt
More file actions
139 lines (112 loc) · 3.42 KB
/
NoteScriptDay1.txt
File metadata and controls
139 lines (112 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
*****************************************************
React NodeJS Docker Workshop Online
*****************************************************
-------------------------------------------------------------
Day 1:
-------------------------------------------------------------
-----
# การขึ้นโปรเจ็กต์ React + Vite + TS + SWC
-----
Step 1: คำสั่งขึ้นโปรเจ็กต์
---
npm create vite@latest
Step 2: ตั้งชื่อโปรเจ็กต์ และเลือกรูปแบบเป็น typescript + swc
---
Project name >> sample-react
Select a framework >> React
Select a variant >> TypeScript + SWC
Step 3: เปิดเข้า VSCode
---
code sample-react -r
Step 4: ติดตั้ง Node dependencies
---
npm install
Step 5: รันโปรเจ็กต์ด้วย Vite
---
npm run dev
-----
การขึ้นโปรเจ็กต์ React + Vite + TS + SWC + Docker
------
Step 1: คำสั่งขึ้นโปรเจ็กต์
---
npm create vite@latest
Step 2: ตั้งชื่อโปรเจ็กต์ และเลือกรูปแบบเป็น typescript + swc
---
Project name >> sample-react-vite-docker
Select a framework >> React
Select a variant >> TypeScript + SWC
Step 3: เปิดเข้า VSCode
---
code sample-react-vite-docker -r
Step 4: เปิด Docker Desktop บนเครื่องขึ้นมา ทดสอบ HelloWorld Docker ดู
---
docker run hello-world
Step 5: สร้าง Dockerfile สำหรับกำหนด script ให้ docker ทำงานกับ image ที่ได้มา
---
# Pull the base image
FROM node:18.16.0-alpine
# Set the working directory
WORKDIR /usr/app
# Copy app dependencies to container
COPY ./package*.json ./
# Install dependencies
RUN npm install
# Copy code from host to container
COPY . .
# Expose Port
EXPOSE 5173
# Deploy app for local development
CMD [ "npm","run","dev" ]
Step 6: การสร้าง Container NodeJS+React ด้วยไฟล์ script ที่เรียกว่า docker-compose.yml
---
version: '3.9'
# Network
networks:
web_network:
name: reactdockervite
driver: bridge
services:
# React App Service
reactapp:
build:
context: .
dockerfile: Dockerfile
container_name: reactapp_vite
restart: always
volumes:
- ./:/usr/app
- /usr/app/node_modules
ports:
- 5173:5173
environment:
- CHOKIDAR_USEPOLLING=true
networks:
- web_network
Step 7: แก้ไขไฟล์ vite.config.js
---
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
server: {
watch: {
usePolling: true,
},
host: true,
strictPort: true,
port: 5173,
}
})
Step 8: ทดสอบว่าไฟล์ docker-compose.yml ทำงานถูกต้องหรือเปล่า
---
docker compose config
Step 9: ทำการ Run เป็น Service และ Container
---
docker compose up -d
ถ้าแก้ไขอะไรใน dockerfile และ docker-compose.yml แล้วจะรันใหม่
---
docker compose up -d --build
-------------------------------------------------------------
Day 2:
-------------------------------------------------------------