Docker - Override or remove ENTRYPOINT from a base image
Asked Answered
G

2

30

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!

Gschu answered 18/12, 2016 at 10:41 Comment(3)
your docker run ends with gatling-nodejs:v7 is it a typo? I thought it would end with 8 instead of7.Comorin
It's a typo, sorry. Just updated! :)Gschu
try in your gatlin.sh cmd1 ; cmd2 ; sleep infinityComorin
G
51

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

Gev answered 18/12, 2016 at 10:48 Comment(4)
This works great but any explanation why? I, for one, was surprised overriding ENTRYPOINT isn't a simple, straightforward matter.Ceil
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.Gev
one can --entrypoint /usr/bin/env with the docker run commandStark
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.Karylkarylin
G
18

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"]
Gschu answered 18/12, 2016 at 11:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.