Jhon Doe Jhon Doe - 4 months ago 15
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

#!/bin/bash

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"