Skip to content

Commit 5907d62

Browse files
author
wtao
committed
dockerize
1 parent ea17d67 commit 5907d62

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

backend/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ COPY . .
1515

1616
# Expose port 4000 to the outside world
1717
EXPOSE 4000
18+
ENV PORT=4000
1819

1920
# Command to run the application
2021
CMD ["node", "index.mjs"]

backend/README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# serverless to AWS lambda
1+
# ways of deployment
22

3-
## AWS setup
3+
## 1. AWS serverless (lambda)
4+
5+
### setup
46

57
you will need an aws api gateway and a new aws lambda function to begin with
68

@@ -16,4 +18,11 @@ sls package
1618
aws s3 cp ./serverless/lambda-mongo-grafana.zip s3://[bucket name]/[path key]
1719

1820
aws lambda update-function-code --function-name [your lambda name] --s3-bucket [bucket name] --s3-key [path key] --region [region of your lambda]
19-
```
21+
```
22+
23+
## 2. Docker container
24+
25+
```bash
26+
docker build -t mongo-grafana .
27+
docker run -d -p 4000:4000 mongo-grafana
28+
```

backend/index.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ app.use((err, req, res, next) => {
2222
});
2323

2424
// start the server
25-
const port = 4000;
25+
// read port from environment variable or default to 4000
26+
const port = process.env.PORT || 4000;
27+
2628
app.listen(port, () => {
2729
console.log(`Server is running on http://localhost:${port}`);
2830
});

0 commit comments

Comments
 (0)