Jhon Doe Jhon Doe - 11 months ago 38
Javascript Question

Run command 'node filename.js' inside a Docker container

I need to run a file js inside a Docker container every day at midnight.

Here's my file midnight.sh


docker exec -it hash_app bash

node midnight.js

Docker exec works fine. But the command 'node midnight.js' doesn't work.

How can I execute midnight.js inside a docker container?

Answer Source

Use -c to send commands as string :

docker exec -it hash_app bash -c "node midnight.js"

Assuming your file is located in /midnight.js otherwise :

docker exec -it hash_app bash -c "cd /path/to/dir;node midnight.js"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download