0

So in a compose file we can override the original CMD with the command instruction:

my-service:
   image: some-image
   command: "custom-command"

And I aware that we can chain multiple commands in a way like this: https://stackoverflow.com/a/30064175/5454794

However the image I use containes and Entrypoint+CMD in a exec form. And I need to preserve the argument defined in the CMD, but if I do any other instruction in the command will be threated as an argument for the entrypoint.sh

ENTRYPOINT [ "/opt/entrypoint.sh" ]
CMD ["-flag", "flag_value"]

So basically what I would like is to run the original ENTRYPOINT with its CMD, then run my script, which needs to be break out from this exec form hell.

edit: I can't modify the dockerfile.

beatrice
  • 3,684
  • 5
  • 22
  • 49

1 Answers1

1

The command in docker-compose file can only override the default command, it cannot add to it. If you can't modify the Dockerfile then you will need to chain the commands in the same way you are referencing

command: bash -c "command1 && command2 && ...

but you will need to manually copy the original command from ENTRYPOINT and CMD in the Dockerfile. So if you have this in your Dockerfile:

ENTRYPOINT [ "/opt/entrypoint.sh" ]
CMD ["-flag", "flag_value"]

then your entrypoint (use entrypoint instead of command to clear both the ENTRYPOINT and CMD set by Dockerfile) in docker-compose will look like

entrypoint: bash -c "/opt/entrypoint.sh -flag flag_value && new_command1 && ..."

From docker documentation

Setting entrypoint both overrides any default entrypoint set on the service’s image with the ENTRYPOINT Dockerfile instruction, and clears out any default command on the image - meaning that if there’s a CMD instruction in the Dockerfile, it is ignored.

Matus Dubrava
  • 13,637
  • 2
  • 38
  • 54
  • For this use you probably need to override `entrypoint:` in the `docker-compose.yml`, if the image is expecting the `command:` part to only be options to its specific program. – David Maze Jul 31 '20 at 12:24
  • You are right, the solution needs to clear both entrypoint and command. – Matus Dubrava Jul 31 '20 at 12:35
  • Thanks. Meanwhile I come to the same conclusion however I solved it the other way around. Meaning clearing entrypoint and setting the original script as a command: entrypoint:[] command: bash -c "/opt/entrypoint.sh -flag flag_value && new_command1 " Dont know which is better – beatrice Jul 31 '20 at 14:29
  • I don't think there is a difference in this case. – Matus Dubrava Jul 31 '20 at 14:55