nestjs build time too long - docker

I want to deploy my NestJS Prisma Docker project, but when I try to build it, it takes a long time and does not deploy or give any error. Could you please help me with this issue? Thank you.
=> CACHED [ 3/11] COPY package*.json ./
=> CACHED [ 4/11] RUN npm install -g npm#latest
=> CACHED [ 5/11] RUN npm install
=> CACHED [ 6/11] RUN npm uninstall argon2
=> CACHED [ 7/11] RUN npm install argon2
=> CACHED [ 8/11] COPY . .
=> CACHED [ 9/11] RUN npx prisma generate
=> CACHED [10/11] RUN ./node_modules/.bin/tsc --extendedDiagnostics
=> [11/11] RUN npm run build
=> => # > simplyjet-backend#0.0.1 prebuild
=> => # > rimraf dist
=> => # > simplyjet-backend#0.0.1 build
=> => # > nest build
This is the problem: it is neither deploying nor giving an error.
dc.test.yml
version: '3.9'
services:
nginx:
image: 'jc21/nginx-proxy-manager:latest'
restart: unless-stopped
ports:
- '80:80'
- '81:81'
- '443:443'
volumes:
- data:/data
- letsencrypt:/etc/letsencrypt
depends_on:
- api
- postgres
- redis
networks:
- simply-jet-backend-api
api:
container_name: simply-jet-api-${NODE_ENV}
image: simply-jet-api-${NODE_ENV}
mem_limit: 8g
environment:
- NODE_ENV=${NODE_ENV}
build:
context: .
dockerfile: Dockerfile
env_file:
- .env.${NODE_ENV}
ports:
- ${APP_PORT}:${APP_PORT}
depends_on:
- postgres
- redis
networks:
- simply-jet-backend-api
restart: unless-stopped
postgres:
container_name: postgres
image: postgres:latest
networks:
- simply-jet-backend-api
env_file:
- .env.${NODE_ENV}
ports:
- ${DB_PORT}:${DB_PORT}
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_DB: '${DB_DATABASE}'
PG_DATA: /var/lib/postgresql/data
volumes:
- pgdata:/var/lib/postgresql/data
restart: always
redis:
image: redis
ports:
- 6379:6379
volumes:
- redis:/data
networks:
- simply-jet-backend-api
pgadmin:
links:
- postgres:postgres
container_name: pgadmin
image: dpage/pgadmin4:latest
ports:
- 5050:80
volumes:
- pgadmin:/root/.pgadmin
env_file:
- .env.${NODE_ENV}
environment:
- PGADMIN_DEFAULT_EMAIL=${PGADMIN_DEFAULT_EMAIL}
- PGADMIN_DEFAULT_PASSWORD=${PGADMIN_DEFAULT_PASSWORD}
networks:
- simply-jet-backend-api
networks:
simply-jet-backend-api:
volumes:
data:
letsencrypt:
pgdata:
redis:
pgadmin:
Dockerfile
FROM node:19
# Create app directory
WORKDIR /app
# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./
# Upgrade npm
RUN npm install -g npm#latest
# Install app dependencies
RUN npm install
RUN npm uninstall argon2
RUN npm install argon2
COPY . .
RUN npx prisma generate
ENV NODE_OPTIONS=--max-old-space-size=4096
ENV NODE_ENV production
RUN ./node_modules/.bin/tsc --extendedDiagnostics
RUN npm run build
CMD [ "npm", "run", "start:prod" ]
I just want to deploy my project. Can someone who is familiar with Docker help me with this?

Related

When creating container into docker-compose on a server. Logs show 'exec /usr/local/bin/docker-entrypoint.sh: exec format error'

Using MacBook M1. (Maybe it's a reason of problem)
During uploading my project into server I got this error
$ cat docker-compose.yml
version: '3.8'
services:
db:
image: postgres:13.0-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- ./.env
restart: always
frontend:
image: annarulunat/foodgram_frontend:latest
volumes:
- ../frontend/:/app/result_build/
backend:
image: annarulunat/foodgram:latest
restart: always
volumes:
- static_value:/app/static_backend/
- media_value:/app/media/
depends_on:
- db
env_file:
- ./.env
command: >
sh -c "python manage.py collectstatic --noinput &&
python manage.py migrate &&
gunicorn foodgram.wsgi:application --bind 0:8000"
nginx:
image: nginx:1.21.3-alpine
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
- ../frontend/build:/usr/share/nginx/html/
- ../docs/:/usr/share/nginx/html/api/docs/
- static_value:/var/html/static_backend/
- media_value:/var/html/media/
restart: always
volumes:
static_value:
media_value:
postgres_data:
$ cat Dockerfile
# build env
FROM node:13.12.0-alpine as build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . ./
RUN npm run build
CMD cp -r build result_build
Thank you)))
I tried to add FROM --platform=linux/amd64 <image>-<version> in the Dockerfile and build

AdonisJS 5 Dockerfile - Cannot find ace

I have a docker setup with AdonisJS 5. I'm currently trying to get it started (and it builds just fine). But as discussed a bit further down, the ace command cannot be found. ace is the CLI package for AdonisJS (think ng for Angular)
This is my Dockerfile:
ARG NODE_IMAGE=node:16.13.1-alpine
FROM $NODE_IMAGE AS base
RUN apk --no-cache add dumb-init
RUN mkdir -p /home/node/app && chown node:node /home/node/app
WORKDIR /home/node/app
USER node
RUN mkdir tmp
FROM base AS dependencies
COPY --chown=node:node ./package*.json ./
RUN npm ci
RUN npm i #adonisjs/cli
COPY --chown=node:node . .
FROM dependencies AS build
RUN node ace build --production
FROM base AS production
ENV NODE_ENV=production
ENV PORT=$PORT
ENV HOST=0.0.0.0
COPY --chown=node:node ./package*.json ./
RUN npm ci --production
COPY --chown=node:node --from=build /home/node/app/build .
EXPOSE $PORT
CMD [ "dumb-init", "node", "service/build/server.js" ]
And this is my docker-compose.yml:
version: '3.9'
services:
postgres:
container_name: postgres
image: postgres
restart: always
environment:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-password}
- POSTGRES_USER=${POSTGRES_USER:-user}
networks:
- family-service-network
volumes:
- fn-db_volume:/var/lib/postgresql/data
adminer:
container_name: adminer
image: adminer
restart: always
networks:
- family-service-network
ports:
- 8080:8080
minio:
container_name: storage
image: 'bitnami/minio:latest'
ports:
- '9000:9000'
- '9001:9001'
environment:
- MINIO_ROOT_USER=user
- MINIO_ROOT_PASSWORD=password
- MINIO_SERVER_ACCESS_KEY=access-key
- MINIO_SERVER_SECRET_KEY=secret-key
networks:
- family-service-network
volumes:
- fn-s3_volume:/var/lib/postgresql/data
fn_service:
container_name: fn_service
restart: always
build:
context: ./service
target: dependencies
ports:
- ${PORT:-3333}:${PORT:-3333}
- 9229:9229
networks:
- family-service-network
env_file:
- ./service/.env
volumes:
- ./:/home/node/app
- /home/node/app/node_modules
depends_on:
- postgres
command: dumb-init node ace serve --watch --node-args="--inspect=0.0.0.0"
volumes:
fn-db_volume:
fn-s3_volume:
networks:
family-service-network:
When I run this with docker-compose up everything works, except for the fn_service.
I get the error:
Error: Cannot find module '/home/node/app/ace'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
node:internal/modules/cjs/loader:936
throw err;
^
I followed this tutorial, and I can't seem to find anything by googling. I'm sure it's something miniscule.
Any help would be appreciated.

Docker: standard_init_linux.go:228: exec user process caused: no such file or directory

I got this docker file:
version: "3.7"
x-web-environment: &web-environment
environment:
- PORT=8000
- ENVIRONMENT_NAME=local_dev
- USING_DOCKER_COMPOSE=true
- DJANGO_SETTINGS_MODULE=backend.settings.dev
- DJANGO_CONFIGURATION=Local
- DJANGO_ALLOWED_HOSTS=web,localhost
- DJANGO_CORS_ORIGIN_WHITELIST
- DJANGO_ADMIN_URL=***
- POSTGRES_USER=documentcrawler
- POSTGRES_PASSWORD=*****
- POSTGRES_HOST=postgres
- POSTGRES_DB=****
- DJANGO_SECRET_KEY=*******************
- REDIS_SERVER_IP=redis
build:
context: ./
dockerfile: Dockerfile.api
volumes:
- type: bind
source: ./
target: /code
- type: bind
source: /tmp
target: /tmp
services:
postgres:
restart: always
image: postgres:14
environment:
- POSTGRES_USER=****
- POSTGRES_PASSWORD=****
- POSTGRES_HOST=*****
- POSTGRES_DB=****
- PGDATA=/data/pgdata
volumes:
- ./pgdata:/data/pgdata
ports:
- "5433:5432"
redis:
restart: always
image: redis:latest
ports:
- "6379:6379"
rabbitmq:
restart: always
image: rabbitmq:3.9
environment:
- RABBITMQ_DEFAULT_USER=****
- RABBITMQ_DEFAULT_PASS=****
ports:
- "5432:5432"
api:
<<: *web-environment
restart: always
ports:
- "8000:8000"
command: "scripts/local/run_web.sh"
app:
restart: always
ports:
- "3000:3000"
environment:
- API_URL=http://api:8000
- INTERNAL_API_URL=http://api:8000
build:
context: ./
dockerfile: Dockerfile.app
ctaima:
<<: *web-environment
restart: always
build:
context: .
dockerfile: Dockerfile
command: ["dramatiq", "-p", "1", "-t", "1", "crawler.tasks.broker:rabbitmq_broker", "--queues", "ctaima"]
shm_size: "4gb"
redis:
image: redis:alpine
ports:
- "6379:6379"
My Dockerfile.api:
FROM python:3.8
ENV PYTHONUNBUFFERED 1
# Add system dependencies
RUN apt update && apt install postgresql gcc python3-dev musl-dev libffi-dev make python3-watchdog -y
# Allows docker to cache installed dependencies between builds
COPY Pipfile* ./
RUN pip install pipenv
RUN pipenv install --dev --system --deploy --ignore-pipfile
# Adds our application code to the image
COPY . /code/
WORKDIR /code
# Expose Django's port
EXPOSE $PORT
#CMD "scripts/local/run_web.sh"
CMD "scripts/local/run_web.sh"
My tree:
scripts/local/run_web.sh
scripts/local/wait_for_postgres.py
scripts/prod/run_web.sh
All containers work perfectly except the API container that generates the error "standard_init_linux.go:228: exec user process caused: no such file or directory"
How can i fix that? thanks u so much!
It is an inherited project that is not mine and I don't know how I can solve it, I hope you can give me a hand.

'Could not find rake-13.0.3 in any of the sources (Bundler::GemNotFound)' while creating my api service

docker-compose.yml
version: "3.7"
services:
courseshine_redis:
container_name: courseshine_redis
image: redis:latest
command: redis-server --requirepass ${POSTGRES_PASSWORD}
restart: always
env_file: .env
stdin_open: true
ports:
- ${REDIS_PORT}:${REDIS_PORT}
volumes:
- courseshine_redis_data:/data
networks:
- internal
courseshine_db:
container_name: courseshine_db
build:
context: ../..
dockerfile: courseshine_docker/development/courseshine_db/Dockerfile
restart: always
env_file: .env
environment:
- POSTGRES_MULTIPLE_DATABASES=${POSTGRES_DEV_DB},${POSTGRES_TEST_DB}
ports:
- ${COURSESHINE_DB_PORT}:${COURSESHINE_DB_PORT}
volumes:
- courseshine_postgres_data:/var/lib/postgresql/data
- ./courseshine_db:/dockerfile-entrypoint-initdb.d
networks:
- internal
courseshine_pgadmin:
container_name: courseshine_pgadmin
image: dpage/pgadmin4:4.21
restart: unless-stopped
env_file: .env
environment:
- PGADMIN_DEFAULT_EMAIL=${POSTGRES_USER}
- PGADMIN_DEFAULT_PASSWORD=${POSTGRES_PASSWORD}
volumes:
- pgadmin:/var/lib/pgadmin
- courseshine_postgres_data:/var/lib/postgresql/data
depends_on:
- courseshine_db
networks:
- internal
courseshine_api: &api_base
container_name: courseshine_api
build:
context: ../..
dockerfile: courseshine_docker/development/courseshine_api/Dockerfile
env_file: .env
stdin_open: true
volumes:
- ../../courseshine_api:/var/www/courseshine/courseshine_api
- /var/run/docker.sock:/var/run/docker.sock
- bundle_cache:/usr/local/bundle
depends_on:
- courseshine_redis
- courseshine_db
networks:
- internal
courseshine_ui:
container_name: courseshine_ui
build:
context: ../../
dockerfile: courseshine_docker/development/courseshine_ui/Dockerfile
env_file: .env
stdin_open: true
volumes:
- ../../courseshine_ui:/var/www/courseshine_ui
depends_on:
- courseshine_api
networks:
- internal
networks:
internal:
volumes:
courseshine_redis_data:
courseshine_postgres_data:
pgadmin:
bundle_cache:
my docerfile for courseshine_api service
FROM ruby:2.7.1-slim-buster
RUN apt-get update -qq && apt-get install -y build-essential nodejs libpq-dev postgresql-client && rm -rf /var/lib/apt/lists/*
ENV APP_HOME /var/www/courseshine/courseshine_api
RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME
COPY ./courseshine_api/Gemfile $APP_HOME/Gemfile
COPY ./courseshine_api/Gemfile.lock $APP_HOME/Gemfile.lock
RUN bundle install --path vendor/cache
# Copy the main application.
COPY ./courseshine_api $APP_HOME
# Add a script to be executed every time the container starts.
COPY ./courseshine_docker/development/courseshine_api/entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
# Expose port 3000 to the Docker host, so we can access it
# from the outside.
EXPOSE 3000
# The main command to run when the container starts. Also
# tell the Rails dev server to bind to all interfaces by
# default.
CMD ["rails","server","-b","0.0.0.0"]
entrypoint.sh
set -e
rm -f $APP_HOME/tmp/pids/server.pid
exec "$#"
when i hit docker-compose up, the courseshine_api service is not stand and throw Could not find rake-13.0.3 in any of the sources (Bundler::GemNotFound). Why this problem occur and how to fix this ..

Docker Error: Cannot cerate container for service <container name>: status code not OK but 500

I used docker-compose to create docker containers in my React, Node.js, and Postgres structured project.
After I created Dockerfile and docker-compose.yml, I did docker up 'docker-compose up --build.'
Then, I wasn't be able to create containers, and get an errors.
I get Error says:
Error 1
Error 2
Error 3
How can I fix it and successfully build containers?
Here is a docker-compose.yml file in './'
version: '3'
services:
server:
container_name: mylivingcity_server
build: ./server
expose:
- 3001
ports:
- 3001:3001
volumes:
- ./server/config:/usr/src/app/server/config
- ./server/controllers:/usr/src/app/server/controllers
- ./server/db:/usr/src/app/server/db
command: npm run start
postgres:
image: postgres:12
container_name: mylivingcity_postgres
ports:
- 5432:5432
volumes:
- ./postgres/data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=mylivingcity
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
frontend:
container_name: mylivingcity_frontend
build: ./frontend
expose:
- 3000
ports:
- 3000:3000
volumes:
- ./frontend/src:/usr/src/app/frontend/src
- ./frontend/public:/usr/src/app/frontend/public
command: npm start
stdin_open: true
Here is a Dockerfile in './frontend'
FROM node:12
# Create frontend directory
RUN mkdir -p /usr/src/app/frontend/
WORKDIR /usr/src/app/frontend/
# Install dependencies
COPY package*.json /usr/src/app/frontend/
RUN npm install
COPY . /usr/src/app/frontend/
CMD [ "npm" , "start" ]
Here is a Dockerfile in './server'
FROM node:12
# Create server directory
RUN mkdir -p /usr/src/app/server/
WORKDIR /usr/src/app/server/
# Install dependencies
COPY package*.json /usr/src/app/server/
RUN npm install
COPY . /usr/src/app/server/
CMD [ "npm" , "run" , "start" ]

Resources