打包镜像
docker build -t xxxxxx-registry.cn-zhangjiakou.cr.aliyuncs.com/test/test-project:v1.1.0 .
推送镜像
docker push xxxxxx-registry.cn-zhangjiakou.cr.aliyuncs.com/test/test-project:v1.1.0
使用同一套代码给 uat 或者生产环境打包镜像
docker images
docker tag [IMAGE ID] xxxxxx-registry.cn-zhangjiakou.cr.aliyuncs.com/prod/test-project:v1.1.0
docker push xxxxxx-registry.cn-zhangjiakou.cr.aliyuncs.com/prod/test-project:v1.1.0
查找标签对应的镜像ID
docker images | grep test/test-project | grep v1.1.0 | awk '{print $3}'
删除镜像
docker rmi --force docker images | grep xxxxxx-registry.cn-zhangjiakou.cr.aliyuncs.com/test/test-project | awk '{print $3}'
删除对应标签的镜像
docker rmi --force `docker images | grep test/test-project | grep v1.1.0 | awk '{print $3}'`
Dockerfile 文件
FROM nginx:alpine
COPY nginx.default.template /etc/nginx/conf.d/default.template
COPY dist /usr/share/nginx/html
EXPOSE 80
WORKDIR /etc/nginx/conf.d
ENTRYPOINT envsubst '${ENV} ${BACKEND1} ${BACKEND2}' < default.template > default.conf && nginx -g 'daemon off;'
nginx.default.template 文件
server {
listen 80;
listen [::]:80;
server_name localhost;
client_header_timeout 1800s;
client_max_body_size 1024m;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
if ($request_uri ~ "\.svg") {
expires 48h;
}
if ($request_uri ~ "\.json") {
add_header Cache-Control no-cache always;
}
# 首页项目缓存问题
if ($request_filename ~* .*\.(?:html)$) {
add_header Cache-Control no-store always;
}
}
# ENV 的值可以为 dev,test,uat,prod,分别对应不同的环境,前端访问config.js的时候,通过${ENV}的值获取不同环境的配置
location = /config.js {
try_files $uri /config/${ENV}.js;
}
# 接口访问地址,前端只访问api,所有接口在 nginx 代理
location /api/ {
proxy_pass ${BACKEND1};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 1800s;
}
# 同上
location /authcode/ {
proxy_pass ${BACKEND2};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 1800s;
}
#error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
ENV、BACKEND1、BACKEND2 在阿里云ACK容器信息中配置环境变量