nginx镜像的使用
最后发布时间 : 2023-02-27 10:59:36
浏览量 :
docker pull nginx:stable-alpine
docker run --rm -it -p 8002:80 -v /ssd2/application/nf-tower:/mnt nginx:stable-alpine sh
构建自定义配置的nginx镜像
FROM nginx:stable-alpine
LABEL version="1.0"
COPY nginx.conf /etc/nginx/nginx.conf
WORKDIR /usr/share/nginx/html
# http://nginx.org/en/docs/ngx_core_module.html#worker_processes
worker_processes auto;
events {
worker_connections 1024;
}
http {
upstream backend {
server localhost:8088;
}
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm;
include /etc/nginx/mime.types;
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
location ~ ^/api/(.*)$ {
proxy_pass http://10.110.1.11:8088/$1$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location / {
try_files $uri $uri/ /index.html;
}
}
}
docker run --rm -p 8002:80 tower-nginx:1.0
docker run --rm -p 8002:80 -v /ssd2/application/nf-tower/tower-web/dist/tower-web:/usr/share/nginx/html tower-nginx:1.0
使用另外一个容器构建js代码
docker pull node:12.0.0-alpine
docker run --rm -it -v /ssd2/application/nf-tower:/mnt node:12.0.0-alpine sh
将构建代码编译与nginx镜像构建合并
# Step 1: Build the app in image 'builder'
FROM node:12.0.0-alpine AS builder
RUN npm config set unsafe-perm true
RUN npm config set registry https://registry.npm.taobao.org
RUN npm install -g @angular/cli
WORKDIR /usr/src/app
COPY . .
RUN npm install -y
RUN npm run build
# Step 2: Use build output from 'builder'
FROM nginx:stable-alpine
LABEL version="1.0"
COPY nginx.conf /etc/nginx/nginx.conf
WORKDIR /usr/share/nginx/html
COPY --from=builder /usr/src/app/dist/tower-web/ .