Question

Issue with nestjs starting - error sh: 1: nest: not found

The dockerised nestjs application runs without error on my local laptop - MacBook. Following a suggestion I created and installed nestjs using the suggestion: https://www.digitalocean.com/community/questions/how-do-i-upload-a-docker-compose-application-that-it-in-github

my dockerfile:

FROM node:16.13.1

WORKDIR /app
COPY package.json .

RUN npm install
COPY . .

CMD npm run start:dev

Package.json:

  • Scripts section: "start:dev": "nest start --watch",
  • Dependencies section: "@nestjs/cli": "^10.1.0"

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

alexdo
Site Moderator
Site Moderator badge
October 25, 2023
Accepted Answer

Heya,

It would be helpful if you could provide more information about the error or issue you’re encountering when running the Dockerized application. Based on the Dockerfile and package.json provided, your setup looks generally correct, but there could be multiple reasons for issues.

Here are a few things to check and consider:

  1. Docker Compose File: Make sure you have a docker-compose.yml file to define how your application should run in Docker. This file specifies the services, networks, and volumes needed for your application. It’s not clear from the information you provided whether you have a docker-compose.yml file, so make sure it’s correctly configured.

  2. Docker Build: Ensure that you have built your Docker image correctly. You can do this by running the following command in the directory containing your Dockerfile:

  1. docker build -t your-app-name .

Replace your-app-name with a suitable name for your Docker image.

  1. Environment Variables: Check if your NestJS application relies on any environment variables. You should pass these variables to your Docker container using the -e flag when running it with docker run, or by defining them in your Docker Compose file under the environment section.

  2. Docker Compose Configuration: Make sure your docker-compose.yml file specifies the correct image to use. Here’s an example of what the service section in your docker-compose.yml might look like:

version: '3' services:   app:     image: your-app-name     ports:       - "3000:3000"     volumes:       - ./app:/app

This assumes that your app runs on port 3000. Adjust the port and volumes as needed.

  1. Network Configuration: Ensure that your NestJS application is binding to the correct host and port inside the Docker container. For example, if your application listens on 0.0.0.0:3000 within the container, it should be accessible at http://localhost:3000 on your host machine.

  2. Docker Compose Build and Run: After creating your Docker image, use docker-compose to build and run your application:

  1. docker-compose up --build

The --build flag ensures that it rebuilds the Docker image as necessary. The application should start, and you should see the logs in the terminal.

If you encounter specific errors or issues, please provide more details, and I can help you further troubleshoot. Additionally, it may be helpful to check the Docker logs for your running container to identify any potential issues:

  1. docker logs container-name

Replace container-name with the actual name or ID of your running container.

You can also check our tutorial on how to build a node.js app with Docker

https://www.digitalocean.com/community/tutorials/how-to-build-a-node-js-application-with-docker

Hope that this helps!

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.