docker 打包前台程序

1. dockerfile

在项目根目录下创建Dockerfile文件

FROM nginx:1.21.1


ADD ./Docker /home/nginx/configs
ADD ./dist /dist
# 运行 nginx
CMD ["nginx","-c","/home/nginx/configs/nginx.conf","-g", "daemon off;"]


EXPOSE 9527 


2. 创建nginx配置文件

/Docker/nginx.conf

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       9527;
        listen       [::]:9527;
        server_name  _;
       # root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

	location / {
 
		root /dist;
		index index.html;	
	}
        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }


}


3. 构建镜像

# 构建镜像
# -t 后表示指定镜像名称 sv3 镜像标签 v1
# . 表示指定 Dockerfile 所在目录
docker build -t sv3:v1 .

4. 运行容器

docker run --name sv3 -p 9527:9527 -v 代码目录:/dist -d sv3:v1

相关推荐

  1. docker 打包前台程序

    2024-03-30 23:42:02       16 阅读
  2. docker-打包&部署

    2024-03-30 23:42:02       8 阅读
  3. Qt程序打包

    2024-03-30 23:42:02       7 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-30 23:42:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-30 23:42:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-30 23:42:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-30 23:42:02       18 阅读

热门阅读

  1. visual studio快捷键

    2024-03-30 23:42:02       18 阅读
  2. Android TV 4K UI

    2024-03-30 23:42:02       15 阅读
  3. Mysql中的那些锁

    2024-03-30 23:42:02       19 阅读
  4. axios请求类型是文件流怎么显示报错信息

    2024-03-30 23:42:02       14 阅读
  5. UI 神器 - Vue3 中如何使用 element-plus

    2024-03-30 23:42:02       18 阅读
  6. Composer常见错误解决

    2024-03-30 23:42:02       22 阅读
  7. 【LeetCode热题100】20. 有效的括号(栈)

    2024-03-30 23:42:02       21 阅读