zoukankan      html  css  js  c++  java
  • [Docker] Create a Docker configuration for a NestJS API

    In this lesson, we add a Docker configuration to our project. In the Dockerfile we specify the different layers of our Docker image. We use a pretty standard Dockerfile and use the build and start scripts in our package.json do the actual work.

    We create a shortcut called docker:build to quickly build an image.

    When building the image, we see that the context being sent to the container is huge. By adding a .dockerignore file we can exclude what is being sent. We add dist and node_modules.

    Other scripts we add are docker:run and docker:push.

    Dockerfile:

    FROM node:14-alpine
    
    WORKDIR /workspace
    
    COPY package.json yarn.lock /workspace/
    
    RUN yarn
    
    COPY . .
    
    RUN yarn build
    
    CMD ["yarn", "start"]

    .dockerignore:

    dist
    node_modules

    scripts:

    "start": "node dist/apps/api/main",
    "build": "nx build api --prod",
    "docker:build": "docker build . -t myapp/api",
    "docker:run": "docker run -it -p 8000:3000 myapp/api",
    "docker:push": "docker push myapp/api",
  • 相关阅读:
    no.5.print sum
    0.1 hint crack
    no.4 抽奖测试
    no2.crossdomain.xml批量读取(待完善)
    no.1
    day7-读写分离
    day6-主从
    day5-备份
    day4-用户授权
    Day3-体系结构+查询+导入/出
  • 原文地址:https://www.cnblogs.com/Answer1215/p/13663751.html
Copyright © 2011-2022 走看看