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!
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:
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.
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:
- docker build -t your-app-name .
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 with docker run
, or by defining them in your Docker Compose file under the environment
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 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.
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.
Docker Compose Build and Run: After creating your Docker image, use docker-compose
to build and run your application:
- 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:
- 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!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
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
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.