Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dockerfile: ENTRYPOINT and CMD

I saw for example in the Dockerfile of the postgres image (https://github.com/docker-library/postgres/blob/master/10/Dockerfile) that at the end the startup of the container is defined like this:

ENTRYPOINT ["docker-entrypoint.sh"]
EXPOSE 5432
CMD ["postgres"]

If I understand this right, the argument postgres is transferred into the docker-entrypoint.sh so $1 in the script is replaced with postgres and the script will be executed.

Now my question is if I can define my own Dockerfile based on the postgres image (FROM postgres) but overwrite the CMD of the base Dockerfile and accomplish to first execute a command on startup and then execute the docker-entrypoint.sh with the postgres argument?

Something like this:

FROM postgres
...
CMD <my-command> && [“postgres”]
like image 436
Palmi Avatar asked Oct 22 '25 22:10

Palmi


1 Answers

You can create you own my-entrypoint.sh

$ cat my-entrypoint.sh
#!/bin/bash

#do what you need here e.g. <my-command>

#next command will run postgres entrypoint will all params
docker-entrypoint.sh "$@"

And your docker file will look as follows

FROM postgres

# your stuff

ENTRYPOINT ["my-entrypoint.sh"]
EXPOSE 5432
CMD ["postgres"]
like image 143
khoroshevj Avatar answered Oct 25 '25 14:10

khoroshevj