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:
"start:dev": "nest start --watch"
,"@nestjs/cli": "^10.1.0"
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!
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.
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:
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 adocker-compose.yml
file, so make sure it’s correctly configured.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:
Replace
your-app-name
with a suitable name for your Docker image.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 withdocker run
, or by defining them in your Docker Compose file under theenvironment
section.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 yourdocker-compose.yml
might look like:This assumes that your app runs on port 3000. Adjust the port and volumes as needed.
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 athttp://localhost:3000
on your host machine.Docker Compose Build and Run: After creating your Docker image, use
docker-compose
to build and run your application: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:
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!