简体   繁体   English

在Docker容器中运行命令'node filename.js'

[英]Run command 'node filename.js' inside a Docker container

I need to run a file js inside a Docker container every day at midnight. 我需要每天午夜在Docker容器中运行一个文件js。

Here's my file midnight.sh 这是我的文件midnight.sh

#!/bin/bash

docker exec -it hash_app bash

node midnight.js

Docker exec works fine. Docker exec工作正常。 But the command 'node midnight.js' doesn't work. 但是命令“ node midnight.js”无效。

How can I execute midnight.js inside a docker container? 如何在docker容器中执行midnight.js?

Use -c to send commands as string : 使用-c以字符串形式发送命令:

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

Assuming your file is located in /midnight.js otherwise : 假设您的文件位于/midnight.js否则:

docker exec -it hash_app bash -c "cd /path/to/dir;node midnight.js"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “node filename.js”在 vs 代码中不起作用 - “node filename.js” is not working in vs code 运行节点fileName.js命令后如何返回终端执行? - How to return to terminal execution after running node fileName.js command? 当我输入终端命令“$ node fileName.js”时,concole 会抛出“SyntaxError: Unexpected token &#39;&lt;&#39;”错误 - When I enter the terminal command "$ node fileName.js" the concole throws out a "SyntaxError: Unexpected token '<'" error 如何在Electron中触发节点filename.js文件? - How to trigger node filename.js file in Electron? jscs 错误:validateLineBreaks:filename.js 处的换行符无效 - jscs error : validateLineBreaks: Invalid line break at filename.js 在运行带端口转发的容器时,没有从node.js代码获取docker容器的IP地址 - Not getting the IP address of the docker container from node.js code when run the container with port forwarding js 文件应该有什么名称,带有奇怪结尾的 url 引导:“.../filename.js?crc=6»? - What names should js files have, to which urls with a strange ending lead: ".../filename.js?crc=6»? 如何在 node.js 中运行交互式 shell 命令? - How to run interactive shell command inside node.js? 在 docker 容器内运行的 node.js 应用程序中找到 docker 名称 - find docker name in a node.js application running inside docker container ver = 3.1.2是什么意思?在ajax.js或filename.js末尾的ver = 3.1.2是什么意思? - What does ver=3.1.2 at the end of ajax.js or filename.js?ver=3.1.2 mean?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM