📢 本文由 gemini-2.5-flash 翻譯
建立新目錄,將網頁檔案放入 ./dict
根目錄建立檔案 dockerfile,內容如下:
1
2
3
4
5
6
| # 基於 nginx:1.20 映像檔
FROM nginx:1.20
# 將 dist 檔案中的內容複製到 /usr/share/nginx/html/ 這個目錄下方
COPY dist/ /usr/share/nginx/html/dist/
# 用本地的 nginx.conf 配置來取代 nginx 映像檔中的預設配置
COPY nginx.conf /etc/nginx/nginx.conf
|
建立新檔案 nginx.conf,內容如下:
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
| #user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
# HTTP server
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html/dist;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
|
執行打包指令
1
| docker build -t username/imagename:v1.0 .
|
tag 修改映像檔名稱
推送映像檔的命名規範
1
| docker push 註冊使用者名稱/映像檔名
|
修改 tag
1
| docker tag name username/imagename:v1.0
|
如果沒有加上 tag,推送時預設為 latest,推送
1
| docker push username/imagename:v1.0
|
參考文章
docker: 打包 H5 專案的映像檔
Docker 映像檔推送(push)到 Docker Hub