Connection refused while connecting to a docker image deployed on Elastic Beanstalk - amazon-web-services

I deployed a docker image running a fluentd instance on Elastic Beanstalk
I want to send messages to fluentd from another Elastic Beanstalk application, but I receive java.net.ConnectException: Connection refused.
in fluend.conf I set
<source>
type forward
bind 0.0.0.0
port 24224
</source>
In Dockerfile i set
EXPOSE 24224
In Dockerrun.aws.json
"Ports": [
{
"ContainerPort": "24224"
}
]
The fluentd node can be pinged from the client node, but it seems that the port 24224 is not exposed correctly to the rest of the environment.
Running the fluentD docker container locally, it works.
Where can I look to solve my problem?

Related

My docker container which is running inside AWS ElasticBeanstalk is not able to connect with the host

My application runs on port 5000 and I have exposed the 5000 port in the docker file.
This is my docker-compose.yml file
"services":
"backend":
"image": "<imageURL>"
"ports":
- "5000:8080"
Container port and application port: 5000
Server port: 8080
The security group of have also been configured properly and the application is able to connect with the database but not working as I try to ping that IP of the server.
My application has an ping API.
Not sure what are you referring to with EBS server as "EBS" is Elastic Block Storage, not the computing
If you're using AWS ECS you need to configure "PortMapping" to map external ports with the container ports
https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_PortMapping.html
If you're using EC2 make sure that your have your service listening to all IPs using the netstat command
netstat -anlp | grep [your port]
and security group inbound and outbound rules are configured properly

AWS Cloud9 IDE "localhost refused to connect." while accessing docker container

In the Step 3 mentioned on https://github.com/stacksimplify/docker-fundamentals/tree/master/03-Pull-from-DockerHub-and-Run-Docker-Images ,
to run http://localhost/hello is throwing error ,
as http is not supported by cloud9 localhost (Reference : https://docs.aws.amazon.com/cloud9/latest/user-guide/troubleshooting.html#troubleshooting-app-preview-http ).
After updating local host port in the command to 443 ; https://localhost/hello getting error : "localhost refused to connect." Already added inbound rule for port 443 at VPC, Subnet and EC2 instance level.
docker run --name app1 -p 443:8080 -d stacksimplify/dockerintro-springboot-helloworld-rest-api:1.0.0-RELEASE
It appears that image is not compatible to run over HTTPS:
OpenSSL: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
Unable to establish SSL connection
Still, please share if you've any pointers to connect localhost on AWS Cloud9 IDE?

Docker container deployed via Beanstalk cannot connect to the database on RDS

I'm new to both docker and AWS. I just created my very first docker image. The application is a backend microservice with rest controllers persisting data in a MySQL database. I've manually created the database in RDS and after running the container locally, the rest APIs work fine in Postman.
Here is the Dockerfile:
FROM openjdk:8-jre-alpine
MAINTAINER alireza.online
COPY ./target/Practice-1-1.0-SNAPSHOT.jar /myApplication/
COPY ./target/libs/ /myApplication/libs/
EXPOSE 8080
CMD ["java", "-jar", "./myApplication/Practice-1-1.0-SNAPSHOT.jar"]
Then I deployed the docker image via AWS Beanstalk. Here is the Dockerrun.aws.json:
{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "aliam/backend",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "8080"
}
],
"Logging": "/var/log/nginx"
}
And everything went well:
But now, I'm getting "502 Bad Gateway" in postman when trying to run "backend.us-east-2.elasticbeanstalk.com/health".
I checked the log on Beanstalk and realized that the application has problem connecting to the RDS database:
"Could not create connection to database server. Attempted reconnect 3 times. Giving up."
What I tried to do to solve the problem:
1- I tried to assign the same security group the EC2 instance is using to my RDS instance, but it didn't work.
2- I tried to make more inbound rules on the security group to add public and private IPs of the EC2 instance but I was not sure about the port and the CIDR I should define and couldn't make it.
Any comment would be highly appreciated.
Here are resources in your stack:
LoadBalancer -> EC2 instance(s) -> MySQL database
All of them need to have SecurityGroups assigned to them, allowing connections on the right ports to the upstream resources.
So, if you assign sg-1234 security group to your EC2 instances, and sg-5678 to your RDS database, there must be a rule existing in the sg-5678 allowing inbound connections from sg-1234 (no need for CIDRs, you can open a connection from SG to SG). The typical MySQL port is 3306.
Similarly, the LoadBalancer (which is automatically created for you by ElasticBeanstalk) must have access to your EC2 instance's 8080 port. Furthermore, if you want to access your instances with the "backend.us-east-2.elasticbeanstalk.com/health" domain name, the loadbalancer would have to listen on port 80 and have a target group of your instances on 8080 port.
Hope this helps!

Spring Boot AWS Elastic Beanstalk - nginx error Connection refused http://127.0.0.1:5000

I'm trying to deploy my Spring Boot application to Elastic AWS Elastic Beanstalk. However the deployment is always in a "Severe" state, with the below being logged into /var/log/nginx/error.log
Connection refused) while connecting to upstream, client: 172.31.10.241, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/
172.31.12.137 - the IP of the EC2 instance
I'm aware that I need to change the server port to 5000 and I have done that in my application.properties file and from the logs I can see that the application has launched on port 5000
TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 5000 (http)
I'm connecting to a MYSQL database on RDS and I can confirm that the application is connecting successfully to that database.
Is there a configuration setting I am missing? Any help would be much appreciated
FYI: I'm not very experienced with AWS
Try using port 8080. You can set SERVER_PORT to 8080 from the Configuration > Software Configuration > Environment Properties in AWS Elastic Beanstalk.
If you are using spring boot application You should add the property server.port=5000 in your application.properties file and also if you are using a profile based property file add the environment variable in the configurations as SPRING_PROFILES_ACTIVE=prod for your profile based property file to be used during run time.

Deploying Docker to AWS Elastic Beanstalk -- how to forward port to host? (port binding)

I have a project set up with CircleCI that I am using to auto-deploy to Elastic Beanstalk. My EBS environment is a single container, auto-scaling, web environment. I am trying to run a service that listens on raw socket port 8080.
My Dockerfile:
FROM golang:1.4.2
...
EXPOSE 8080
My Dockerrun.aws.json.template:
{
"AWSEBDockerrunVersion": "1",
"Authentication": {
"Bucket": "<bucket>",
"Key": "<key>"
},
"Image": {
"Name": "project/hello:<TAG>",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "8080"
}
]
}
I have made sure to expose port 8080 on the "role" assigned to my project environment.
I used the exact deployment script from the CircleCI tutorial linked above (except with changed names).
Within the EC2 instance that is running my EBS application, I can see that the Docker container has run successfully, except that Docker did not forward the exposed port to the host container. I have encountered this in the past when I ran docker run .... without the -P flag.
Here is an example session after SSH-ing into the machine:
[ec2-user#ip-xxx-xx-xx-xx ~]$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a036bb061aea aws_beanstalk/staging-app:latest "/bin/sh -c 'go run 3 days ago Up 3 days 8080/tcp boring_hoover
[ec2-user#ip-xxx-xx-xx-xx ~]$ curl localhost:8080
curl: (7) Failed to connect to localhost port 8080: Connection refused
What I expect to see is the ->8080 or whatever in the container that forwards it onto the host.
When I do docker inspect on my container, I also see that these two configurations are not what I want:
"PortBindings": {},
"PublishAllPorts": false,
How can I trigger a port binding in my application?
Thanks in advance.
It turns out I made a misunderstanding in how Docker's networking stack works. When a port is exposed but not published, it is still available to the local network interface through the Docker container's private IP address. You can obtain this IP address by checking docker inspect <container>.
Rather than doing curl localhost:8080 I could do curl <containerIP>:8080.
In my EBS deploy, nginx was automatically setup to forward (HTTP) traffic from Port 80 to this internal private port as well.
I had the same problem in a rails container (port 3000 using puma) by default rails server only binds localhost to the listening interface, I had to use -b option to bind 0.0.0.0 and that solved the problem.
In react I have no the same problem cause npm serve package binds all interfaces by default