29

I'm using Docker (version 1.12.2, build bb80604) to setup a simple image/container with Gatling (Load Testing tool) + NodeJS. So, I pulled this Docker/Gatling base image and created my own Dockerfile to install NodeJS on it.

However, the Docker/Gatling base image above has an ENTRYPOINT already defined to call Gatling straightaway and then automatically exits the container. It looks like this:

ENTRYPOINT ["gatling.sh"]

What I'm trying to achieve is: I want to run a second command (my own NodeJS script to parse the test results), however I couldn't find a solution so far (I tried overriding the ENTRYPOINT, different combinations of ENTRYPOINT and CMD, but no success).

Here is how my current Dockerfile looks like:

FROM denvazh/gatling:2.2.3

RUN apk update \
&& apk add -U bash \
&& apk add nodejs=6.7.0-r0

COPY simulations /opt/gatling/user-files/simulations
COPY trigger-test-and-parser.sh /opt/gatling/

RUN chmod +x /opt/gatling/trigger-test-and-parser.sh

ENTRYPOINT ["bash", "/opt/gatling/trigger-test-and-parser.sh"]

Here is the command I'm using to build my image based on my Dockerfile:

docker build --no-cache -t gatling-nodejs:v8 .

And this is the command I'm using to run my container:

docker run -i -v "$PWD/results":/opt/gatling/results -v "$PWD":/opt/gatling/git.campmon.com/rodrigot/platform-hps-perf-test gatling-nodejs:v8

And this is the shellscript (trigger-test-and-parser.sh) I'd like to execute once the container starts (it should trigger Gatling and then runs my NodeJS parser):

gatling.sh -s MicroserviceHPSPubSubRatePerfTest.scala
node publish-rate-to-team-city.js

Any ideas or tweaks so I can run both commands once my container starts?

Thanks a lot!

user2253130
  • 589
  • 2
  • 5
  • 14

2 Answers2

47

Set ENTRYPOINT to /usr/bin/env. Then set CMD to be what you want run.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
  • 1
    This works great but any explanation why? I, for one, was surprised overriding `ENTRYPOINT` isn't a simple, straightforward matter. – skytreader Dec 28 '18 at 00:26
  • 2
    There in no way to delete an ``ENTRYPOINT`` setting in a base image, so the only option is to replace it with something else. The ``/usr/bin/env`` program is convenient in that respect as it will execute any command you give as argument. See the man page for ``env`` for more details of using it to do that. – Graham Dumpleton Dec 28 '18 at 04:10
  • one can --entrypoint /usr/bin/env with the docker run command – yolob 21 Aug 13 '21 at 16:26
  • One quick note to explain it further: We cannot just override ENTRYPOINT with a blank value (i.e. `[]`), so using env will allow us override it and then everything we give to CMD will be passed to env, causing it to run them portably, just like we add shebangs such as `#!/usr/bin/env bash` at the top of shell scripts. – aderchox Oct 31 '21 at 12:52
15

Graham's idea above worked pretty well. Thanks again!

For future reference, here is the two lines I had to add to my Dockerfile:

ENTRYPOINT ["/usr/bin/env"]

CMD ["bash", "/opt/gatling/trigger-test-and-parse-result.sh"]
user2253130
  • 589
  • 2
  • 5
  • 14