Reputation: 882
I have a simple MEAN application, which I compose using a Mongo image and a Node + Express image. I use Elastic Beanstalk to create a Docker Application. I am able to create an environment successfully. EB dashboard tells me that both the application and the environment were successfully created.
However the URL for my EB instance gives me a 502 Bad Gateway. I researched this error in relation to Beanstalk and variously tried:
Adding a NodeCommand: "npm start"
property to .ebextensions/node-command.config
which gave me a Duplicate or Invalid property
error.
Mimicking the way the project is started as detailed in this repo: https://github.com/shippableSamples/sample_node_eb_docker/tree/tutorial
I am following this tutorial; http://blog.shippable.com/how-to-deploy-to-elastic-beanstalk-part-2, which uses the aforementioned project as an example.
Basically, I moved the app.listen
code under bin/www
None of these approaches worked.
My Dockerfile
FROM node:7
RUN mkdir -p /usr/src/rishighan
WORKDIR /usr/src/rishighan
COPY package.json /usr/src/rishighan
COPY bower.json /usr/src/rishighan
#Install dependencies
RUN npm i -g bower && \
npm i && \
bower i --config.interactive=false --allow-root
RUN npm rebuild node-sass
COPY . /usr/src/rishighan
EXPOSE 80
# This starts the app
CMD npm start
docker-compose.yml
# find a way to seed the mongo db
version: '3.2'
services:
mongodb:
build:
context: ./
dockerfile: mongo-seed/Dockerfile
web:
build: .
command: node server.js
volumes:
- .:/usr/src/rishighan
ports:
- "3000:3000"
links:
- mongodb
environment:
PORT: 3000 # this is optional, allows express to use process.env.PORT instead of a raw 3000
Dockerrun.aws.json
{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "frishi/rishighanangular_web:nativeEBDeployment",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "80"
}
],
"Volumes": [
]
}
Relevant bits of my package.json
"scripts": {
"dev": "webpack-dev-server --content-base app/ --hot --inline",
"start": "webpack -w --debug --devtool eval --output-pathinfo",
"local-dev": "node server.js",
"test": "testem ci"
}
Relevant bits of my server.js
// Start Server on 3000
let port = process.env.PORT || 3000;
app.listen(port, function () {
console.log("Server listening on port ", port);
});
I also found an answer on SO that suggested overriding the nginx.conf
before Beanstalk sets it. I was able to download logs from EB and they are as follows:
nginx error.log
2017/07/24 12:10:47 [error] 3378#0: *8824 connect() failed (111: Connection refused) while connecting to upstream, client: 10.65.133.248, server: , request: "GET / HTTP/1.1", upstream: "http://172.17.0.2:80/", host: "54.243.122.6"
2017/07/24 13:27:16 [error] 3378#0: *9903 connect() failed (111: Connection refused) while connecting to upstream, client: 10.164.151.69, server: , request: "GET /xmlrpc.php HTTP/1.1", upstream: "http://172.17.0.2:80/xmlrpc.php", host: "54.197.241.240"
2017/07/24 13:29:18 [error] 3378#0: *9946 connect() failed (111: Connection refused) while connecting to upstream, client: 10.164.151.69, server: , request: "GET / HTTP/1.1", upstream: "http://172.17.0.2:80/", host: "54.197.241.240"
2017/07/24 14:17:28 [error] 3378#0: *10615 connect() failed (111: Connection refused) while connecting to upstream, client: 10.65.133.248, server: , request: "GET / HTTP/1.1", upstream: "http://172.17.0.2:80/", host: "rishighan-angular-dev.us-east-1.elasticbeanstalk.com"
2017/07/24 14:17:28 [error] 3378#0: *10615 connect() failed (111: Connection refused) while connecting to upstream, client: 10.65.133.248, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://172.17.0.2:80/favicon.ico", host: "rishighan-angular-dev.us-east-1.elasticbeanstalk.com", referrer: "http://rishighan-angular-dev.us-east-1.elasticbeanstalk.com/"
I would appreciate any pointers as to where to start looking for potential causes of the error.
Upvotes: 1
Views: 1506
Reputation: 912
Had a similar issue myself, and the problem was that nginx connects to node.js on port 8081 by default. I can see in your code that you're trying to listen on port 3000 by default.
Upvotes: 0