Deploy Node Express API via Docker Compose on EC2 - amazon-web-services

In my EC2, I pulled my Docker images from my ECR : API + WEB
I then start both of them up via Docker Compose
It seems to start fine, but I don't know why I can't seem to go to my API.
I can go to my site
When I go to my API, I see this
I already open up the 3002 port on my EC2 inbound rule
docker-compose.yml
version: "2"
services:
iproject-api:
image: '616934057156.dkr.ecr.us-east-2.amazonaws.com/bheng-api-script:latest'
ports:
- '3002:3002'
iproject-web:
image: '616934057156.dkr.ecr.us-east-2.amazonaws.com/bheng-web-script:latest'
ports:
- '80:8080'
links:
- iproject-api
Did I forgot to restart any service?

Inbound rule looks fine. Check your API code status in EC2 docker logs {API_Container_Id}/telnet localhost 3002

Related

Dockerized Spring Boot on AWS Beanstalk not accessible

I have deployed a Spring boot app to AWS Beanstalk through Github action but it is not accessible. Set up Spring boot to run on port 5000 and exposed it because from my understanding beanstalk open the port 5000. Watching the AWS logs I see that Spring boot correctly starts at port 5000. Below my configuration files:
Dockerfile.dev
FROM eclipse-temurin:17-jdk-alpine
VOLUME /tmp
ADD /target/demoCI-CD-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
EXPOSE 5000
This is the link not working: http://dockerreact-env.eba-v2y3spbp.eu-west-3.elasticbeanstalk.com/test
Having a docker-compose.yml in the project beanstalk takes it in consideration and there was the issue with port mapping. Below the correct map porting in docker-composer.yml.
version: "3"
services:
web:
build:
context: .
dockerfile: Dockerfile.dev
ports:
- "80:8080"

How to map host port and container port in AWS Fargate and AWS Beanstalk for a docker deployment?

I am trying to deploy a web application in AWS fargate as well as AWS Beanstalk.
my docker compose file looks like this.(just an example , please focus on ports)
services:
application-gateway:
image: "gcr.io/docker-public/application:latest"
container_name: application-name
ports:
- "443:9443"
- "8443:8443"
**Issue with AWS Fargate
**
I need to know how to map these ports - Bridge doesnt get enabled and I see only
How to change Host Port
I can see that once I deploy the public docker image it gets deployed in Fargate however how to access the application DNS URL ?
**Issue facing in AWS Beanstalk
**
I was able to deploy the application in single instance however I am unable to deploy it in application load balanced enviroment. again I suspect the issue is with the ports in load balancer , I have opened these ports in security group though.
Thanks,

Docker Compose ECS Service fails when using a provided LoadBalancer

I am deploying a compose to an AWS ECS context with the following docker-compose.yml
x-aws-loadbalancer: "${LOADBALANCER_ARN}"
services:
webapi:
image: ${DOCKER_REGISTRY-}webapi
build:
context: .
dockerfile: webapi/Dockerfile
environment:
ASPNETCORE_URLS: http://+:80
ASPNETCORE_ENVIRONMENT: Development
ports:
- target: 80
x-aws-protocol: http
When I create a loadbalancer using these instructions the loadbalancer assigns the default security group for the default vpc. Which apparently doesn't match the ingress rules for the docker services because if I go and look at the task in ECS I see it being killed over and over for failing an ELB healtcheck.
The only way to fix it is to go into AWS Console and assign the created security group created by docker compose to represent the default network to the loadbalancer. But thats insane.
How do I create a loadbalancer with the correct minimum access security group so it will be able to talk to later created compose generated services?

Unable to access chronograf UI running on EC2 instance port 8888 in a docker container

I started Chronograf on an EC2 instance on port 8888. My EC2 instance is running Ubuntu. When I ssh into the instance and do
curl <my_ec2_public_DNS>:8888
I get a valid response.
Now when I try to go the URL http://<my_ec2_public_DNS>:8888 from a browser on my computer, my request always times out. I am able to ping <my_ec2_public_DNS> from my computer.
My EC2 security inbound rules are as follows:
Please help.
Edit 1: I am running chronograf in a docker container.
chronograf:
image: chronograf:latest
volumes:
- ./my_dir/data/:/var/lib/chronograf/
ports:
- "8888:8888"
depends_on:
- influxdb

How to create api endpoint after created the docker container on ec2

I've created a docker container for my server on ec2 using nodejs.
I wonder what is the next step I should do if I want to create an rest API endpoint for public access.
Dockerfile
FROM node:lts-alpine
WORKDIR /server
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3030
CMD ["npm", "run", "dev"]
docker-compose.yml
version: '2.1'
services:
test-db:
image: mysql:5.7
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=true
- MYSQL_USER=admin
- MYSQL_PASSWORD=12345
- MYSQL_DATABASE=test
volumes:
- ./db-data:/var/lib/mysql
ports:
- 3306:3306
test-web:
environment:
- NODE_ENV=local
#- DEBUG=*
- PORT=3030
build: .
command: >
./wait-for-db-redis.sh test-db npm run dev
volumes:
- ./:/server
ports:
- "3030:3030"
depends_on:
- test-db
From your comments its seems that you want to use https for your endpoint. And probably this is the greatest thing to setup, assuming you already own a domain, e.g. myapi.com. If you don't have a domain, you have to buy one if you want custom url.
There are several possibilities to add https:
Add nginx to your application as extra container, which will accept connections on port 443 and forward to your app on port 3030. nginx can be setup to use https. For that you need valid, public ssl certificates from a third party (e.g. letsencrypt). You could AWS ACM to get them, but for instance they only work with nitro-enclave instances. For instance you can use EIP and target Route53 record from your domain to the EIP.
Front you instance with Load Balancer (LB). This is the easiest to setup, as you can get free SSL certs from ACM, and deploy them on the LB. Set your Route53 domain to point to LB url as an alias record.
Setup API Gateway or CloudFront distro in-front of your EC2 instance. The issue is that connections between the API/CF and your instance will go over HTTP, unless you setup valid SSL certificates on your instance, like in the first possibility. You will also need EIP for the instance, or front it with LB, before using API Gateway or CloudFront.