How to execute sails js in docker - node.js

I am using docker for my sails js project. Any idea how to check which command was used to run sails.js. I have tried History command but its not giving me previous command which was run
Can anybody tell me how to check the which command was used before to execute the sailsjs? I need to restart my sails.js

To check what command used to run to make it started in docker, try
docker ps -a --no-trunc --format "{{.ID}}: {{.Command}}"
It will show the full command for sailsjs for the container.

Related

Start an interactive node.js CLI app with docker-compose up

I made a node.js interactive CLI app to let communicate our intern work log with jira.
It works without problems, but I want to make it cross platform using docker.
The idea is to start docker and start inside the container the CLI, and than close the CLI and close also the container.
Now, to start my app I just give npm start. I managed to create a docker container and run the app inside, but to start the app I have to docker-compose exec app bash and then npm start
I want to do it during the container start up process, in order to give just docker-compose up and start to use my CLI.
Is that in any way possible?
I tried to add commands: "bash -c npm start" to my docker-compose file, and it works, but the output is not interactive. I see my app in the docker log but I can not interact with it.
Ideas?

Laradock - add custom npm package

It's a kind of not normal thing, but this is something, that temporarily is a solution.
I have laradock installed in a system and laravel app.
All that I'm using from laradock provides me command below
docker-compose up -d nginx mysql php-worker workspace redis
I need to add node package (https://www.npmjs.com/package/tiktok-scraper) installed globally in my docker, so I can get results by executing php code like below
exec('tiktok-scraper user username-n 3 -t json');
This needs to be available for php-fpm and php-worker level, as I need this in jobs and for endpoints, that should invoke scrape.
I know, that I'm doing wrong, but I have tried to install it within workspace like using
docker-compose exec workspace bash
npm i -g tiktok-scraper
and after this it's available in my workspace (I can run for instance tiktok-scraper --help) and it will show me the different options.
But this doesn't solve the issue, as I'm getting nothing by exec('tiktok-scraper user username-n 3 -t json'); in my laravel app.
I'm not so familiar with docker and not sure, in which dockerfile should I put something like
RUN npm i -g tiktok-scraper
Any help will be appreciated
Thanks
To execute the npm package from inside your php-worker you would need to install it in the php-worker container. But for the php exec() to have an effect on your workspace this workspace would need to be in the same container as your php-worker.

pm2: command not found in ec2 when running script file

after deploying node.js project using gitlab CICD successfully when try to execute script.sh file which is in side project folder it shows
./script.sh: line 3: pm2: command not found
I want to restart pm2 server after deploying node.js file
now , if I run this script.sh file after ssh into my ec2 from terminal it execute successfully.
here is my script.sh file
Help me to solve this ,
Thank You in advance :)
Okay so , after tried many possibles ways I have find that first go into your root in ec2 using sudo su and then install npm & pm2 into root directory.
after this you can able to run pm2 command from script file.
Also if you can add the below commands and check, it's worked for me.
sudo ln -s "$(which pm2)" /usr/bin/pm2
I worked in AWS EC2 instance.

Node+NPM on Laradock

I followed everything on the documentation on how to enable NPM on the workspace. However, when I run docker-compose exec workspace bash then check node -v it is missing. The document didn't say too how to use it.
Restart docker-compose by using the following commands:
docker-compose stop
docker-compose restart
Once workspace is up, exec workspace and verify node -v again.

setting up a docker container with a waiting bash to install npm modules

I'm trying to do something pretty trivial. For my dev environment, I wish to be able to have a shell in my container so I can run commands like npm install or npm run xxx.
(I do not want to install my npm modules during build, since I want to map them to the host so that my editor is able to find them on the host. I do not want to execute npm install on the host, since I don't want the host to have to install npm).
So even though in a production container I would instruct my container to just run node, in my developer container I want to have an always waiting bash.
If I set entrypoint to /bin/bash, the container immediately exits. This means that I can't attach to it anymore (since it stopped) and starting it will just immediately exit it again.
I tried writing a small .sh to just loop and start /bin/bash again, but using that in my ENTRYPOINT yields an error that it can't find the .sh file, even though I know it is in the container.
Any ideas?
You can use docker exec to run commands in a given container.
# Open an interactive bash shell in my_container
docker exec -it my_container bash
Alternatively, you can use docker run to create a new container to run a given command.
# Create a container with an interactive bash shell
# Delete the container after exiting
docker run -it --rm my_image bash
Also, from the question I get the sense you are still in the process of figuring out how Docker works and how to use it. I recommend using the info from this question to determine why your container is exiting when you set the entrypoint to /bin/bash. Finding out why it's not behaving as you expect will help you to understand Docker better.
I'm not sure what command you are trying to run, but here's my guess:
Bash requires a tty, so if you try to run it in the background without allocating one for it to attach to, it will kill it self.
If you're wanting to run bash in the background, make sure to allocate a tty for it to wait on.
As an example, docker run -d -it ubuntu will start a bash terminal in the background that you can docker attach to in the future.

Resources