代码之家  ›  专栏  ›  技术社区  ›  Edward

Docker angular nginx return 403 Forbidden

  •  0
  • Edward  · 技术社区  · 4 年前

    我正在尝试使用docker映像配置angular,并使用 docker-compose .

    这是我的码头文件

    # Use official node image as the base image
    FROM node:16-alpine3.12 as build
    
    # Set the working directory
    WORKDIR /usr/local/app
    
    # Add the source code to app
    COPY ./ ./
    
    # Install all the dependencies
    RUN npm install
    
    # Generate the build of the application
    RUN npm run build:prod
    
    
    # Stage 2: Serve app with nginx server
    
    # Use official nginx image as the base image
    FROM nginx:latest
    
    # Copy the build output to replace the default nginx contents.
    COPY --from=build /usr/local/app/dist/ /usr/share/nginx/html
    #COPY /nginx.conf  /etc/nginx/conf.d/default.conf
    # Assign permisson 
    # https://stackoverflow.com/questions/49254476/getting-forbidden-error-while-using-nginx-inside-docker
    # RUN chown nginx:nginx /usr/share/nginx/html/*
    
    # Expose port 80
    EXPOSE 80
    EXPOSE 443
    

    如果我运行,它会正确运行 docker build docker run 本地。但是,在用下面的yml推送到github之后:

    name: Docker Image CI For Web
    
    on:
      push:
        tags:
          - 'web-v*'
    
    jobs:
      push_to_registry:
        name: Push Docker image to Docker Hub
        runs-on: ubuntu-latest
        steps:
          - name: Check out the repo
            uses: actions/checkout@v2
          - name: Log in to Docker Hub
            uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
            with:
              username: ${{ secrets.DOCKER_USERNAME }}
              password: ${{ secrets.DOCKERHUB_TOKEN }}
          - name: Extract metadata (tags, labels) for Docker
            id: meta
            uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
            with:
              images: edward8520/meekou
          - name: Build and push Docker image
            uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
            with:
              context: ./angular/
              file: ./angular/Dockerfile
              push: true
              tags: ${{ steps.meta.outputs.tags }}
              labels: ${{ steps.meta.outputs.labels }}
    

    然后跑 码头工人组成 在下面,

    version: '3.9'
    services:
        meekou-web:
            container_name: 'meekou-web-test'
            image: 'edward8520/meekou:web-v0.0.4'
            ports: 
                - "8888:80"
                - "8889:443"
            environment:
              - NODE_ENV=production
            volumes:
              - ./meekou-web/:/usr/share/nginx/html
            expose:
              - "80"
              - "443"
    

    它抛出错误 403 Forbidden

    0 回复  |  直到 4 年前
    推荐文章