When I run nestjs with docker compose, the microservices redirects don't work, but in the "nest start" command, the application plays as I want.
gateway api response
connect ECONNREFUSED 127.0.0.1:3000
gateway | at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
gateway | errno: -111,
gateway | code: 'ECONNREFUSED',
gateway | syscall: 'connect',
gateway | address: '127.0.0.1',
gateway | port: 3000
gateway | }
Code
docker-compose.yml
services:
auth:
container_name: auth
restart: always
build:
context: ./auth
dockerfile: dockerfile
ports:
- 3000:3000
networks:
- docker_dev_cloud
gateway:
container_name: gateway
restart: always
build:
context: ./gateway
dockerfile: dockerfile
ports:
- 4000:4000
networks:
- docker_dev_cloud
networks:
docker_dev_cloud:
driver: bridge
gateway dockerfile
Code
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 4000
CMD [ "npm", "run", "start:dev" ]
auth dockerfile
Code
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD [ "npm", "run", "start:dev" ]
help me please.
move localhost to service name for example:
127.0.0.1:3000 to
auth:3000
Related
To whom it may concern,
Im trying to run my app with docker compose file and get an error:
This is my docker-compsoe file
version: '3.8'
services:
backend:
container_name: backend
build:
context: .
dockerfile: ./docker/Dockerfile.backend-dev
restart: always
ports:
- '5000:5000'
env_file:
- ./apps/backend/envs/.env.development
volumes:
- type: bind
source: ./apps/backend/src
target: /app/apps/backend/src
- /app/apps/backend/node_modules
frontend:
container_name: frontend
build:
context: .
dockerfile: ./docker/Dockerfile.frontend-dev
restart: always
ports:
- '3000:3000'
volumes:
- type: bind
source: ./apps/frontend/src
target: /app/apps/frontend/src
- /app/apps/frontend/node_modules
And this is my dockerfile of the frontend
FROM node:18.14.0
RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm
WORKDIR /app
COPY ./package.json ./pnpm-workspace.yaml ./.npmrc ./
COPY ./apps/frontend/package.json ./apps/frontend/
RUN pnpm i -w
RUN pnpm --filter frontend i
COPY ./tsconfig.base.json ./
COPY ./apps/frontend/ ./apps/frontend/
CMD ["pnpm", "-F", "frontend", "start" ]
And this is the error
apps/frontend start$ vite -c ./vite.config.ts
apps/frontend start: failed to load config from /app/apps/frontend/vite.config.ts
apps/frontend start: error when starting dev server:
apps/frontend start: Error: Cannot find module '#vitejs/plugin-react'
Here is my pnpm workspace.yaml file
packages:
- 'apps/*'
Please help
When running docker-compose up -d
i am trying to dockerize Nuxt js app and nest js in the backend
I want it now for development
i have 2 folders, eva-frontend and eva-backend
I get them up and runnig on docker but when i want to change something in the frontend code, docker doesn't detect it. In backend it works, so i guess that there is something wrong with my volume
The other problem is when i go to my application i login and when i refresh the page i should login again
locally on my pc i don't have this problem, only on docker
so i guess there is something wrong with my Volume in the front end
dockerfile backend:
FROM node:16.15.1-alpine
WORKDIR "/app"
COPY . .
RUN npm install
EXPOSE 3001
CMD [ "npm", "run", "dev"]
dockerfile frontend:
FROM node:16.15.1-alpine
WORKDIR "/app"
COPY package.json ./
COPY . .
RUN npm install
EXPOSE 3000
ENV NUXT_HOST=0.0.0.0
ENV NUXT_PORT=3000
CMD [ "npm", "run", "dev" ]
docker-compose.yml
services:
frontend:
build: ./eva-frontend
depends_on:
- backend
ports:
- 3000:3000
volumes:
- ./eva-frontend:/app
backend:
build: ./eva-backend
ports:
- 3001:3001
volumes:
- ./eva-backend:/app
I try to connect to Redis from my backend, but I keep getting the following error:
...
api-1 | [ioredis] Unhandled error event: Error: getaddrinfo ENOTFOUND undefined
api-1 | at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26)
api-1 | [ioredis] Unhandled error event: Error: getaddrinfo ENOTFOUND undefined
api-1 | at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26)
...
Here is how I config my redis client:
import Redis from "ioredis";
export const redisConfig = () => {
if (process.env.NODE_ENV === "production") {
return `redis://${process.env.REDIS_HOST}:${process.env.REDIS_PORT}`;
}
return "";
};
const redisCli = new Redis(redisConfig());
export default redisCli;
And this is my dockerfile:
# ---- Dependencies ----
FROM node:16-alpine AS base
# minimize image size
RUN apk add --no-cache libc6-compat
RUN npm install -g npm#latest
WORKDIR /app
COPY ./package*.json ./
RUN npm ci
# ---- Builder ----
FROM node:16-alpine AS builder
RUN npm install -g npm#latest
WORKDIR /app
COPY --from=base /app/node_modules ./node_modules
COPY ./src ./src
COPY package*.json tsconfig.json webpack.config.ts ./
RUN npm run build
# ---- Release ----
FROM node:16 AS release
WORKDIR /app
# COPY ./prisma ./prisma
# COPY ./.env ./
# COPY ./deployment ./deployment
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./
# RUN npx prisma generate
RUN npm install pm2 -g
EXPOSE 3000
This one is the docker-compose.yml:
version: "3"
services:
api:
build: ./
depends_on:
- redis
links:
- redis
command: sh -c "node dist/server.js"
environment:
- REDIS_HOST=redis
- REDIS_PORT=6379
- NODE_ENV=production
ports:
- 3000:3000
redis:
image: "redis:latest"
I have specified the links in docker-compose, but still receiving the same error.
How can I fix the error? Thanks for any help!!
You are receiving this error because your application is probably trying to connect to redis before redis is up and accessible. In your depends_on section, you can say that you want to start your application after your redis service is healthy. To do so, you must also configure a healthcheck to tell when redis is really ready to accept connections (redis-cli ping for example).
Here is an example of configuration that works for me:
version: "3"
services:
api:
build: ./
depends_on:
redis:
condition: service_healthy
links:
- redis
environment:
- REDIS_HOST=redis
- REDIS_PORT=6379
- NODE_ENV=production
redis:
image: redis:latest
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 1s
timeout: 2s
retries: 10
Was able to connect with such a config into the Redis hosted in Docker
ConfigurationOptions co = new ConfigurationOptions()
{
SyncTimeout = 500000,
EndPoints =
{
{ "127.0.0.1", 49155 }
},
AbortOnConnectFail = false // this prevents that error,
, Password = "redispw"
};
RedisConnectorHelper.lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
{
return ConnectionMultiplexer.Connect(co);
});
where 49155 is the doker path port
Here is default.vcl
vcl 4.1;
backend default {
.host = "127.0.0.1";
.port = "8080";
}
My docker-composer.yml
version: "3"
services:
varnish:
image: varnish:stable
container_name: varnish
volumes:
- "./default.vcl:/etc/varnish/default.vcl"
ports:
- "80:80"
tmpfs:
- /var/lib/varnish:exec
environment:
- VARNISH_SIZE=2G
depends_on:
- "node"
node:
build: ./
container_name: node
ports:
- "8080:8000"
My Dockerfile
FROM node:10-alpine
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
WORKDIR /home/node/app
COPY package*.json ./
USER node
RUN npm install
COPY --chown=node:node . .
EXPOSE 8080
CMD [ "node", "app.js" ]
When I run the application through http://localhost:8080/ it works and when I run it directly in port 80 like this http://localhost/ it throws
Error 503 Backend fetch failed
Am I missing out something in configuring port? Or How can I check the varnish log through docker?
I am stuck in building the docker containers for MERN stack E-commerce app. These are my following Docker files and Docker compose files. I am getting this error
enter image description here
# Dockerfile for React client
# Build react client
FROM node:lts-buster-slim
# Working directory be app
WORKDIR /usr/src/app
COPY package.json /usr/src/app
COPY package-lock.json /usr/src/app
### Installing dependencies
RUN npm ci
# copy local files to app folder
COPY . /usr/src/app
EXPOSE 3000
CMD ["npm","start"]
# Dockerfile for Node Express Backend
FROM node:lts-buster-slim
# Create App Directory
WORKDIR /usr/src/app
# Install Dependencies
COPY package.json /usr/src/app/package.json
COPY package-lock.json /usr/src/app/package-lock.json
RUN npm ci
COPY . /usr/src/app
# Exports
EXPOSE 5000
CMD ["npm", "run", "dev"]
version: "3.7"
services:
frontend:
build: frontend
ports:
- 3000:3000
stdin_open: true
volumes:
- ./frontend:/usr/src/app
- /usr/src/app/node_modules
container_name: frontend
restart: always
networks:
- react-express
depends_on:
- backend
backend:
container_name: backend
restart: always
build: backend
volumes:
- ./backend:/usr/src/app
- /usr/src/app/node_modules
depends_on:
- mongo
networks:
- express-mongo
- react-express
ports:
- 5000:5000
mongo:
container_name: mongo
restart: always
image: mongo:4.2.0
volumes:
- ./data:/data/db
networks:
- express-mongo
ports:
- 27017:27017
networks:
react-express:
express-mongo:
I am getting this error when I execute the command: "docker-compose up". I am doing a MERN E-Commerce App. The error is: backend | /bin/sh: syntax error: unterminated quoted string
backend exited with code 2