How do I run a Docker pre-entrypoint command without knowing the original entrypoint?

6/2/2020

I can not find a clear answer to this particular use case!

I have an arbitrary docker image, let's say postgres:latest, this has a 'baked in' entrypoint of some complex command that fires up the postgres server.

What I want to do is run a command, say apt install ca-certificates && wget 'MyTimestampedCAConfig' as an example, and then call the original (unknown) entrypoint to start the database.

The context I am doing this in is in Kubernetes by supplying a custom command: in the yml. docker run --entrypoint is more or less equivalent.

I can find the original command for the postgres:latest container manually in this specific case via docker history, and hard code it into the kube-yml. But this doesn't work in an environment with hundreds of custom containers and the endpoints periodically and quite randomly change...

How do I dynamically call the original entrypoint after my own command?

-- GDev
docker
kubernetes

1 Answer

6/2/2020

How do I dynamically call the original entrypoint after my own command?

You can't. There is no way to say "call the entrypoint script of the base image after the entrypoint script in my custom image". The only solution is to determine the original entrypoint using e.g. docker inspect and then call that explicitly from your own entrypoint script.

Do you really need to override the entrypoint script for your use case? The example you've given (installing a new package) seems it would best be solved by creating a new image based on the postgres image and then adding the necessary RUN apt install ... command to the Dockerfile.

-- larsks
Source: StackOverflow