Reputation: 17825
I've made a Dockerrun.aws.json
file that defines two Docker images I want to run with AWS Elastic Beanstalk. One is an nginx container with a static front-end website and API routing, and the other is the backend API. But for some reason the container linking isn't working and the nginx container can't forward requests to the API.
Whenever nginx tries to proxy_pass
requests, I get this error:
2018/01/02 22:03:01 [error] 5#5: *22 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.1.70, server: localhost, request: "POST /api/auth/login HTTP/1.1", upstream: "http://172.17.0.2:5000/api/auth/login", host: "my-app-dev.us-west-2.elasticbeanstalk.com", referrer: "http://my-app-dev.us-west-2.elasticbeanstalk.com/login"
From reading this aws multi-container documentation it looks like links are just made automatically?
Here's my nginx file:
server {
listen 4000;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm;
# Matches any request with a file extension. Adds cache headers.
location ~ .*\..* {
try_files $uri =404;
expires 1y;
access_log off;
add_header Cache-Control "public";
}
# Matches api requests and redirects to the api server's port.
location /api {
proxy_pass http://api:5000;
}
# Any route that doesn't have a file extension. This helps react router route page urls using index.html.
location / {
try_files $uri $uri/ /index.html;
}
}
And my Dockerrun.aws.json
file:
{
"AWSEBDockerrunVersion": "2",
"containerDefinitions": [
{
"name": "proxy",
"image": "my-app/proxy:1",
"essential": true,
"memory": 64,
"portMappings": [
{
"hostPort": 80,
"containerPort": 4000
}
],
"links": [
"api"
]
},
{
"name": "api",
"image": "my-app/api:1",
"essential": true,
"memory": 128
}
]
}
This same setup is working locally with docker-compose
but something about how I'm trying to do it with aws is obviously not correct.
Upvotes: 1
Views: 2099
Reputation: 17825
It appears that my java app was silently unresponsive due to an insufficient amount of memory. Upgraded my aws instance and changed "memory": 128
to "memory": 512
and it works. No networking issue after all.
An even better solution is changing "memory" to "memoryReservation". That way I define a minimum required memory, but it can still make use of as much of the EC2 instance's additional memory as is available.
Upvotes: 0
Reputation: 398
From the nginx error log above, nginx is able to resolve the upstream server endpoint as 172.17.0.2:5000
which means nginx docker container is able to resolve the ip of api docker container
The error thrown was Connection Refused
which be can caused by
5000
is not exposed by the api docker container 172.17.0.2
) is incorrectFor the first case you can go SSH into the EC2 instance and check the api docker container information and see whether 5000
port is exposed, if the port is not exposed then Dockerfile
should be modified to expose the port
Second and third case should not happen as it is taken care by AWS
Anyways to verify second and third case, you can SSH into the EC2 instance which are running the docker containers and then connect to the nginx container and do a telnet 172.17.0.2 5000
, if it does not succed there is clearly a network issue
Upvotes: 1