I try to deploy a NodeJS (NestJS) application on Ec2 instance, so I create Ec2 instance and connect to them via ssh, install Git, Node, Docker, Docker-compose etc. When I run only nest start
to run my node.js app then everything is fine and I see my app from the browser (but only when I set MyIP in inbound rules, why? - I've had also all Http/Https rules...).
But I can't do this in this way because I have to use docker-compose with two services - Api and Redis.
my docker-compose looks like here:
version: '3.7'
networks:
proxy:
name: proxy
services:
redis:
image: redis:6.2-alpine
ports:
- 6379:6379
command: ["redis-server", "--requirepass", "redisPass12345!"]
networks:
- proxy
worker:
container_name: worker
build:
context: .
dockerfile: Dockerfile
depends_on:
- redis
ports:
- 8080:8080
expose:
- '8080'
- '3005'
env_file:
- .env
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
command: npm run dev
networks:
- proxy
When I build and up docker-compose with:
sudo docker-compose up
and open browser then I see that this site cannot be reached
... Can someone tell me what have i doing wrong?
here is also my Dockerfile:
FROM node:16.3.0-alpine as builder
WORKDIR /dist
COPY package*.json ./
RUN npm install --force
COPY . .
RUN npm run build
EXPOSE 8080
CMD [ "npm", "run", "dev"]
PS. One more thing, my process.env.PORT
is set to 3005
.
CodePudding user response:
If your application is listening on port 3005, you should expose this port also in your docker-compose.yaml, and also in the AWS inbound rules.
Try to docker ps
to and see which port at exposed for your nodejs application.