Dokku showing errors in console - node.js

I have node.js app which I deploying with Dokku, for the first after deployment app crashed and Docker container closed, so I checked my project on my computer again and found error. How can I debug errors on Dokku? Is there any console?

What you want is to see logs of the container running your node.js app. But as the container is closed you cannot attach to it to see outputs from stdout and stderr.
You can however see logs of closed containers.
To do so, first run docker ps -a, this will output even closed containers.
Then use docker logs <container-id> with the id of the closed container to fetch logs and debug your app.

I have an easier solution if you don't feel like messing with process management.
Dokku provide tools to help you manage your apps from the client.
The dokku-toolbelt is installed with npm :
npm install -g dokku-toolbelt
Once installed, open the command line from your app directory (or cd to it).
Now that you are in the good directory, you can use dt logs to see the latest console log.
If you want more "real time" logs, type dt logs -t. You can now see every console.log() (and more) from you nodejs dokku app.
Happy debug !

Related

Error running nextjs with PM2 on Azure App Service on Linux

The pipelines and releases seem to work finely as they get the artifact deployed on the app service or so it seems as the output error happens on start of the PM2 process.
I haven't found anything on this error on google, and don't know if there is a way to update PM2 on the app service machine as PM2 itself suggests.
These are the logs.
Error message
summary image
I was expecting the app to work and no longer show an application error as I fixed both build and release pipelines.
This is a picture of the important bit of info of the error as its really long
Check the below steps to run nextjs with PM2.
First create a nextJS app.
Run npm run dev command to run the app in development.
Deploy the app to Azure Linux App Service.
Open the SSH of the Azure App Service to run the PM2 commands.
We can open directly with the below URL.
Path to SSH - https://YourDeployedAppName.scm.azurewebsites.net/
OR
Navigate to the deployed Azure Linux App => Advanced Tools => Go => SSH.
Run the below command to install PM2.
npm install pm2 -g
Thanks #Azure OSS Developer Support for the commands.
In Configuration section => General Settings add the Startup command.
pm2 start site/root/index.js --name mynpmnextapp
Your path may differ for the index.js file.
My app entry point is index.js.For some apps it can be server.js.Change it according to your app.
cannot find module `../build/output/log'
Make sure you are not running the PM2 with the output folder. As mentioned above it has to be the entry point either server.js or index.js based on your code files.
don't know if there is a way to update PM2 on the app service
In the KUDU Console use npm install pm2#latest -g to update the PM2.
References taken from MSDoc and npmjs.

Debug dockerized nodejs application on startup

I have a setup of containers running ( docker-compose ) and one with a nodejs application running inside of it. Currently i debug the application by connecting via VS Code to the debug port (9229) of the application. The problem with this approach is that i can't connect to the application on startup. If the error is on some event like an http connection that is no problem, but if i want to check the initialisation process the process is already running for some time until i can connect so the process ran past my debug points.
Is there a solution to this?
Run the following commands to find the running container and navigate into the container...
List all Docker images: docker image ls
View contents of a running Docker container: docker exec -it <container-id> bash
once inside the container, then you can stop the node process inside the container and start by node app.js where you will be able to see the logs from initialisation Or if you have a logs file then there aswell you can check.
The basic idea here is to navigate inside the docker container and then its like running node server like how you would run normally from ay linux terminal.

Node.js app stops working as soon as the AWS Lightsail's Bitnami console is closed

I have developed a simple node.js application and I am trying to publish it on AWS Lightsail. I followed the instructions on this page: https://medium.com/#sharmasha2nk/aws-lightsail-bitnami-nodejs-letsencrypt-cf653573b8a1
I am connecting to Bitnami using the SHH console provided. After I start the app with node index.js command the app is up and running until I close the SHH console. As soon as I close it the application stops and “Service Unavailable” error is being displayed. How can I keep my app running on AWS even if my PC is shot down and the SHH console is closed?
I have tried restarting the apache server and AWS Lightsail instance. Neither of them helped.
httpd-app.conf file content:
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
httpd-prefix.conf file content:
Include "/opt/bitnami/apps/emsnotes/conf/httpd-app.conf"
Thanks.
I would recommend you pm2
Here's how to do it quickly:
install pm2 globally using sudo npm i -g pm2
navigate to the location of your index.js via ssh
run pm2 start index.js
This will keep node running even when you disconnect the ssh session or shutdown your development computer. The process will keep running on your server in the background. This is used for running node apps in production on a server.
You can read all about it here in its documentation.
I hope I could help you, please let me know if you have any question.
Karim
I had a look at the article and frankly i see nowhere that he talk about keeping the server up and running.
Basically he is using the Bitnami Node.js stack and if you look at the docs you will see that Bitnami use Forever.js to keep the apps running on their instance, Forever is a CLI tool to monitor and keep a Node instance running in the background.
Check the docs here : https://docs.bitnami.com/general/infrastructure/nodejs/administration/start-express-server/
Here is the Git for Forever, so can read more on it: https://github.com/foreverjs/forever

Ubuntu where to see console.logs

So I am putting my app on a server and I want to see some console logs generated from my nodejs app. Before putting it on the server I saw the output of my console log on my terminal, but where do I find the output for these on Ubuntu? I'm running version 16.04 on Ubuntu
Lifted straight from #SlovyanskiyYehor comment two years ago, but I missed his answer as a comment. Also answered here: Make pm2 log to console.
If you are using pm2 to start your node.js application, you can use:
pm2 logs
or for just a single app running in pm2:
pm2 logs yourAppNameHere
If you are using some bash script which is runed by cron for example,
you can specify file where you need to output all logs of your app
It will looks like that:
myApp > /path/to/logs/myAppLogs.txt
This command will run application myApp and put all logs into
"/path/to/logs/myAppLogs.txt"
Also you can put this string into cron directly without some bash scripts
Of course you can see all console logs by user here ~/.bash_history
but it`s not always useful
If you used pm2, you can check log in this folder:
/root/.pm2/log

Azure Docker Container - how to pass startup commands to a docker run?

Faced with this screen, I have managed to easily deploy a rails app to azure, on docker container app service, but logging it is a pain since the only way they have access to logs is through FTP.
Has anyone figured out a good way to running the docker run command inside azure so it essentially accepts any params.
in this case it's trying to simply log to a remote service, if anyone also has other suggestions of retrieving logs except FTP, would massively appreciate.
No, at the time of writing this is not possible, you can only pass in anything that you would normally pass to docker run container:tag %YOUR_STARTUP_COMMAND_WILL_GO_HERE_AS_IS%, so after your container name.
TLDR you cannot pass any startup parameters to Linux WebApp except for the command that needs to be run in the container. Lets say you want to run your container called MYPYTHON using the PROD tag and run some python code, you would do something like this
Startup Command = /usr/bin/python3 /home/code/my_python_entry_point.py
and that would get appended (AT THE VERY END ONLY) to the actual docker command:
docker run -t username/MYPYTHON:PROD /usr/bin/python3 /home/code/my_python_entry_point.py

Resources