<p>I have the following nodejs dockerfile:</p>
<pre><code># pull image
FROM node:13.12.0-alpine

# set working directory
WORKDIR /app

# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH

# install app dependencies
COPY package.json ./
COPY package-lock.json ./
RUN npm install

# add app
COPY . ./

# start app
CMD node server dev
</code></pre>
<p>I need to dynamically run a custom JS script inside the container after start up. How can I achieve this?</p>
<p>UPDATE:
I tried adding the following entry point after CMD, but neither CMD not ENTRYPOINT was executed:</p>
<pre><code>ENTRYPOINT node customScript.js
</code></pre>
<p>Added a wrapper shell script (startup.sh) to include both commands:</p>
<pre><code>#!/bin/sh

nohup node server dev &gt; startup.log &amp;&amp; node data/scripts/custom.js &gt; custom.log
</code></pre>
<p>Replaced CMD with:</p>
<pre><code>CMD [&quot;./startup.sh&quot;]
</code></pre>
<p>This only executes the first command in the shell and not the second. I also don't see the output-redirect log files being created in the container.</p>

sotn
<p>ideally, you should be running the process of <strong>nohup</strong> in background</p>
<p>there is no issue due to <strong>CMD</strong> or <strong>ENTRYPOINT</strong></p>
<pre><code>#!/bin/sh

nohup node server dev &gt; startup.log &amp;&amp; node data/scripts/custom.js &gt; custom.log
</code></pre>
<p>use <strong>&amp;</strong> last at your <strong>nohup</strong> command to start the process into backgroud mode</p>
<pre><code>nohup ./yourscript &amp;
</code></pre>
<p><strong>or</strong></p>
<pre><code>nohup command &amp;
</code></pre>
<p>after this you can run the <strong>node</strong> command</p>
<p><strong>sh</strong> example</p>
<pre><code>nohup nice &quot;$0&quot; &quot;calling_myself&quot; &quot;$@&quot; &gt; $nohup_out &amp;
node index.js
sleep 1
tail -f $nohup_out
</code></pre>
