[Docker] Create a Docker configuration for a NestJS API
2023-09-14 08:59:13 时间
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",
相关文章
- 通过Docker部署一个NSFW JS搭建一个私有的图片鉴黄API
- 从零开始 - Docker部署前后端分离项目(三)
- docker 权限问题 Got permission denied while trying to connect to the Docker daemon socket at 。。。「建议收藏」
- Kafka入门实战教程(2)基于Docker搭建Kafka环境
- Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
- docker安全三:k8s集群环境搭建
- Docker image build failed on Mac M1 chip
- 修改Docker中nginx容器默认的端口号配置[通俗易懂]
- docker安装postgresql
- docker导出容器为镜像_docker如何将容器打包成镜像
- Docker常用命令大全,看这篇文章就够了!
- Docker命令大总结,主要微服务项目部署
- 启动docker镜像命令_什么是docker镜像
- Docker学习4-常用命令之重要的容器命令
- 一篇文章教你实战Docker容器数据卷
- 【已解决】Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon runnin
- Docker服务的停止命令(systemctl stop docker)
- Docker查看容器命令(docker ps)
- docker使用笔记III -- docker的快速安装
- docker系统源加速命令
- Docker部署MinIO
- 【Docker 系列】docker 学习 一,Docker的安装使用及Docker的基本工作原理
- docker中安装es和kibana
- Docker教程(超全总结)
- 使用docker部署应用时出现中文乱码要如何处理
- Docker容器的重启策略及docker run的–restart选项详解程序员
- 探索Linux系统 API 的乐趣(linux系统api)
- Linux加密API:安全加固保护您的数据(linux加密api)
- 探索Linux驱动API:开启发展之路(linux驱动api)
- Linux图形界面API:开启简单而强大的开发之旅(linux图形界面api)
- MySQL异步API:为高性能加载提升极限(mysql异步api)
- Docker-命令帮助以及验证
- MySQL中文API:数据操作更便捷(mysql中文api)
- 简易指南:轻松使用Redis 常用API(redis常用api)
- 深入了解Linux文件API,掌握Linux文件操作技巧(linux文件api)
- 使用C语言搭建MySQL数据库API(c语言mysql api)
- MySQL C语言API应用注意事项(mysqlc语言api)
- MySQL的C API之旅让我们开始吧(c api访问mysql)
- Oracle数据库中的中文API丰富性研究(oracle 中文api)
- Redis实现API调用计数限制(redis限制api次数)