Docker で H5 イメージを作成・プッシュする

📢 この記事は ChatGPT によって翻訳されました

新しいディレクトリを作成し、Web ファイルを ./dict に配置する。

プロジェクトルートに dockerfile ファイルを作成し、以下の内容を記述:

1
2
3
4
5
6
# nginx:1.20 ベースのイメージを使用
FROM nginx:1.20
# dist フォルダの内容を nginx の静的ファイルディレクトリへコピー
COPY dist/ /usr/share/nginx/html/dist/
# 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 {
        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 でイメージ名を変更する

Docker Hub にプッシュする際の命名規則:

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

This post is licensed under CC BY-NC-SA 4.0 by the author.

Visits Since 2025-02-28

Hugo で構築されています。 | テーマ StackJimmy によって設計されています。