code-8
code-8

Reputation: 58730

Deploy NodeJS Express API to AWS

I used CodeFresh to build my Docker Image and push to AWS ECR.

enter image description here

I check my ECR, I can see the pushed there successfully.

enter image description here

I SSH into my EC2, I don't see any content there.

enter image description here


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

enter image description here

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 │
└──────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────┴───────────┴──────┴──────────┘

Upvotes: 0

Views: 297

Answers (1)

Adiii
Adiii

Reputation: 60074

First thing

By doing ls does not mean it will show the docker image.

If the docker images pull successfully then check it using below command.

docker images

This will print all the images that are running in this ec2 container instance. something like 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 ps

This will print running container.

copy the id of the container and run this command.

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.

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
  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.

You can also view tasks events using AWS console under ECS -> cluster -> service -> tasks

If some thing went wrong you will see in the events like

enter image description here

If every thing ok then

enter image description here

Complete image

enter image description here

Upvotes: 3

Related Questions