Tuesday, April 17, 2018

Docker run a command in an image

How many times you are baffled because you run

docker run myregistry/maven:3-alpine

and it simply exists without doing anything.

Then you do

docker run myregistry/maven:3-alpine /bin/bash

and the same thing happens

Then you inspect the image:

docker image inspect myregistry/maven:3-alpine


and you notice

           "Cmd": [
                "mvn"
            ],

          "Entrypoint": [
                "/usr/local/bin/mvn-entrypoint.sh"
            ],


and you wonder what is actually executed....

Luckily you can simply OVERRIDE the entrypoint (see https://gist.github.com/mitchwongho/11266726 ) :


docker run -it --entrypoint /bin/bash myregistry/maven:3-alpine

so you enter directly a bash shell, without executing the original Entrypoint of course.


The documentation of this precious Maven image is https://hub.docker.com/_/maven/ here

mvn settings are in /usr/share/maven/ref/settings-docker.xml and (maybe) in /usr/share/maven/conf/settings.xml
mvn binaries are in /usr/bin/mvn -> /usr/share/maven/bin/mvn


Ref: docker run https://docs.docker.com/engine/reference/commandline/run/#options


Priceless, to debug Maven: mvn -X help:effective-settings



No comments: