Home Docker 创建与推送 H5 镜像
Post
Cancel

Docker 创建与推送 H5 镜像

新建目录,将网页文件放入 ./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
29
#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

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

设计模式 Index

JavaWeb 入门