zoukankan      html  css  js  c++  java
  • dockerfile指令

    案例

     构建go(gin)项目

    FROM golang:alpine
    
    # 为我们的镜像设置必要的环境变量
    ENV GO111MODULE=on 
        CGO_ENABLED=0 
        GOOS=linux 
        GOARCH=amd64 
        GOPROXY="https://goproxy.cn,direct"
    
    WORKDIR /home/www/iter
    
    # 将代码复制到容器中
    COPY . .
    
    RUN go mod tidy
    # 将我们的代码编译成二进制可执行文件  可执行文件名为 app
    RUN go build -o app ./main.go
    
    ## 移动到用于存放生成的二进制文件的 /dist 目录
    WORKDIR /dist
    #
    #二进制文件
    RUN cp /home/www/iter/app .
    
    # 声明服务端口
    EXPOSE 9089
    
    # 启动容器时运行的命令
    CMD ["/dist/app"]
    View Code

    构建node项目

    FROM node:latest
    
    WORKDIR /3d_chooser_service
    COPY . .
    
    RUN npm --registry https://registry.npm.taobao.org install
    
    RUN npm run build
    
    EXPOSE 3000
    
    CMD node ./service/app.js
    View Code

     nginx

    FROM nginx:1.16
    
    COPY dist/ /usr/share/nginx/html
    
    COPY default.conf /etc/nginx/conf.d/default.conf
    
    EXPOSE 80
    View Code

    default.conf

    server {
    
      listen 80;
      server_name localhost; #填写绑定证书的域名
    
      root /usr/share/nginx/html;
    
      # Add index.php to the list if you are using PHP
      index index.php index.html index.htm index.nginx-debian.html;
    
      location /dev-api {
        proxy_set_header Host $host; #保留代理之前的host
        proxy_set_header X-Real-IP $remote_addr; #保留代理之前的真实客户端ip
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header HTTP_X_FORWARDED_FOR $remote_addr; #在多级代理的情况下,记录每次代理之前的客户端真实ip
    
        #       limit_req zone=myRateLimit burst=20 nodelay;
    
        proxy_pass http://192.168.10.231:9031/;
        proxy_redirect default; #指定修改被代理服务器返回的响应头中的location头域跟refresh头域数值
    
      }
    
      location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        #try_files $uri $uri/ =404;
        #   limit_req zone=myRateLimit burst=20 nodelay;
        index index.html index.php index.htm index.nginx-debian.html;
        try_files $uri $uri/ /index.html;
    
      }
    
    
    
    }
    View Code

     java

    FROM openjdk:8-jdk-alpine
    #启动jar包
    VOLUME /tmp
    
    ADD hongyi-system/target/hongyi-system-1.0.0.jar app.jar
    
    #RUN bash -c "touch /app.jar"
    
    EXPOSE 8086
    
    ENTRYPOINT ["java", "-jar", "app.jar", "--spring.profiles.active=dev", "--server.port=8086", "> /log/app.log"]
    View Code

     go

    FROM golang:latest
    WORKDIR /root/micro-go-course/section10/userCOPY//root/micro-go-course/section10/user
    RUN go env-w GOPROXY=https://goproxy.cn,directRUN go build -o user
    ENTRYPOINT["./user"]
    View Code

    指令

    CMD  启动指令,某些情况下时必要的

  • 相关阅读:
    3. 算法分析
    4. union-find算法
    1.基础编程模型和数据抽象
    2. 背包,队列和栈
    .NET Core 单元测试
    ASP.NET Core Web API
    ASP.NET Core MVC 之区域(Area)
    ASP.NET Core MVC 之依赖注入 Controller
    ASP.NET Core MVC 之依赖注入 View
    微服务架构学习与思考(04):微服务技术体系
  • 原文地址:https://www.cnblogs.com/huay/p/11174212.html
Copyright © 2011-2022 走看看