简体   繁体   English

将NodeJS Express API部署到AWS

[英]Deploy NodeJS Express API to AWS

I used CodeFresh to build my Docker Image and push to AWS ECR. 我使用CodeFresh构建我的Docker映像并推送到AWS ECR。

在此处输入图片说明

I check my ECR, I can see the pushed there successfully. 我检查了我的ECR,可以看到成功推送到那里。

在此处输入图片说明

I SSH into my EC2, I don't see any content there. 我通过SSH进入EC2,那里看不到任何内容。

在此处输入图片说明


Update 更新

[ec2-user@ip-10-0-0-47 share]$ docker ps                                                                                                                            
CONTAINER ID        IMAGE                                                    COMMAND             CREATED             STATUS              PORTS               NAMES  
1e4d4eae6520        616934057156.dkr.ecr.us-east-2.amazonaws.com/bheng-api   "sh cmd.sh"         29 hours ago        Up 29 hours         3002/tcp            ecs-api-1-bheng-api-88ef95c7ddc993badf01                                                                                                                                   
44b78781d487        amazon/amazon-ecs-agent:latest                           "/agent"            30 hours ago        Up 30 hours                             ecs-agent                                                                                                                                                                  
[ec2-user@ip-10-0-0-47 share]$                                                                                                                                      
[ec2-user@ip-10-0-0-47 share]$                                                                                                                                      
[ec2-user@ip-10-0-0-47 share]$ docker images                                                                                                                        
REPOSITORY                                               TAG                 IMAGE ID            CREATED             SIZE                                           
616934057156.dkr.ecr.us-east-2.amazonaws.com/bheng-api   latest              41e9eaa2aff2        29 hours ago        952MB                                          
amazon/amazon-ecs-agent                                  latest              622111e45fde        6 weeks ago         29.4MB                                         
amazon/amazon-ecs-pause                                  0.1.0               b875fd8f097a        6 weeks ago         963kB                                          
[ec2-user@ip-10-0-0-47 share]$                                                                                                                                      
[ec2-user@ip-10-0-0-47 share]$                                                                                                                                      
[ec2-user@ip-10-0-0-47 share]$

This is the security group of my EC2 这是我的EC2的安全组

在此处输入图片说明

PM2 PM2

Use --update-env to update environment variables
[PM2] Applying action restartProcessId on app [all](ids: 0)
[PM2] [index](0) ✓
┌──────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────┬───────────┬──────┬──────────┐
│ App name │ id │ mode │ pid   │ status │ restart │ uptime │ cpu │ mem       │ user │ watching │
├──────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────┼───────────┼──────┼──────────┤
│ index    │ 0  │ fork │ 23901 │ online │ 1       │ 0s     │ 0%  │ 12.8 MB   │ node │ disabled │
└──────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────┴───────────┴──────┴──────────┘

First thing 第一件事

By doing ls does not mean it will show the docker image. 通过执行ls并不意味着它将显示docker映像。

If the docker images pull successfully then check it using below command. 如果docker镜像成功提取,则使用以下命令进行检查。

docker images

This will print all the images that are running in this ec2 container instance. 这将打印在此ec2容器实例中运行的所有图像。 something like 56789.dkr.ecr.us-east-2.amazonaws.com/bheng-api:latest . 类似于56789.dkr.ecr.us-east-2.amazonaws.com/bheng-api:latest

As for debugging is a concern you need to check is your docker container is running. 至于调试是一个问题,您需要检查您的Docker容器是否正在运行。

docker ps

This will print running container. 这将打印正在运行的容器。

copy the id of the container and run this command. 复制容器的ID并运行此命令。

docker exec -it {container_id} bash|ash

docker logs 码头工人日志

docker logs  {container_id}

You can also check how images is working by assigning role to your ece container instace and run the following command. 您还可以通过将角色分配给ece容器实例来检查映像的工作方式,然后运行以下命令。

docker run -it --rm -p 80:80 56789.dkr.ecr.us-east-2.amazonaws.com/bheng-api:latest

Again I will mention the steps 我会再次提及步骤

  1. create ECR and push ur docker image 创建ECR并推送您的docker镜像
  2. create Task definition 创建任务定义
  3. create service that runs the instance of that task definition. 创建运行该任务定义实例的服务。 with out service there will be nothing like container or docker image. 没有服务,将不会有像容器或码头工人形象。 once u create service you will se docker image in your ec2 instance. 创建服务后,您将在ec2实例中设置docker映像。

You can also view tasks events using AWS console under ECS -> cluster -> service -> tasks 您还可以使用ECS->集群->服务->任务下的AWS控制台查看任务事件

If some thing went wrong you will see in the events like 如果出现问题,您会在类似的事件中看到

在此处输入图片说明

If every thing ok then 如果一切都好,那

在此处输入图片说明

Complete image 完整图片

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM