Here's how one can modify container commands without building another image.
- Pull the image
docker pull sonarsource/sonar-scanner-cli
- Inspect it
docker inspect sonarsource/sonar-scanner-cli
You should get something like this:
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD ["sonar-scanner"]" <- arguments
],
"WorkingDir": "/usr/src",
"Entrypoint": [ <- executable
"/usr/bin/entrypoint.sh"
],
Entrypoint
is what will be executed and CMD [...]
(not Cmd
) are the arguments for the executable. In a human-friendly format that equals to:
# entrypoint args
/usr/bin/entrypoint.sh sonar-scanner
Now in this case we have a script that is being executed so there are two options.
Option 1: Modify the entrypoint script and mount it at launch
- Run this to save the script on your machine:
docker run --rm --entrypoint="" sonarsource/sonar-scanner-cli /bin/cat /usr/bin/entrypoint.sh > entrypoint.sh
- Modify
entrypoint.sh
as you like, then put its contents into a configMap.
- Mount the file from the configMap instead of /usr/bin/entrypoint.sh (don't forget to set mode to
0755
)
Option 2: Change entrypoint and arguments in resource definition
Note that this may not work with some images (ones with no shell inside).
- name: "sonarqube-scan-{{ .Values.git.commitID }}"
image: "{{ .Values.harbor.host }}/{{ .Values.harbor.cache }}/sonarsource/sonar-scanner-cli"
command: # this is entrypoint in k8s API
- /bin/sh
- -c
args: # this goes instead of CMD
- "before.sh && /usr/bin/entrypoint.sh sonar-scanner && after.sh"
# | original command and args |
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…