1. 根目录配置 conf/nginx/nginx.conf
user nginx; worker_processes auto;
error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid;
events { worker_connections 1024; }
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
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;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
2. 根目录配置 conf/nginx/default.conf
server {
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
3. 根目录创建dockerfile
FROM nginx:1.22.1
COPY unpackage/dist/build/h5/ /usr/share/nginx/html/
COPY conf/nginx/nginx.conf /etc/nginx/nginx.conf
COPY conf/nginx/default.conf /etc/nginx/conf.d/default.conf
WORKDIR /usr/share/nginx/html
4. 生成镜像
docker build -t 镜像名字:v1.0.0 . // v1.0.0指镜像版本
5. 查看镜像的image ID
docker images
6. 启动容器及制定端口
docker run -p 9009:80 --name 修改名字 -d 83f090241561 //9009指定端口 83f090241561 为镜像id