Dockerfile: ENTRYPOINT and CMD

Palmi

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”]
khoroshevj

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"]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Dockerfile without CMD or Entrypoint

confused with CMD and ENTRYPOINT in dockerfile

Understanding Dockerfile CMD/ENTRYPOINT

Dockerfile entrypoint/cmd not executing on container import

What is the difference between CMD and ENTRYPOINT in a Dockerfile?

Use here document with ENTRYPOINT/CMD in Dockerfile

CMD doesn't run after ENTRYPOINT in Dockerfile

Dockerfile - exec form of ENTRYPOINT and shell form of CMD

Combining ENTRYPOINT and CMD in Dockerfile targeting different executables

Dockerfile CMD unable to locate entrypoint file

dockerfile: how use CMD or ENTRYPOINT from base image

Dockerfile ENTRYPOINT ignores WORKDIR

dockerfile : npm not found at entrypoint?

Dockerfile ENTRYPOINT with parameters

Dockerfile Entrypoint issue

Entrypoint clause not working in the dockerfile

Dockerfile Entrypoint Bash script run upon start, then run npm script with appendable CMD argument

Docker entrypoint and cmd together

exec not found using Dockerfile ENTRYPOINT

Access dockerfile ENV variables in entrypoint

Dockerfile execute additional scripts in entrypoint

Entrypoint file not being found for Dockerfile

Not possible to override command with CMD or Entrypoint

Docker: understanding ENTRYPOINT and CMD instructions

Dcokerfile pass ENV to ENTRYPOINT or CMD

Docker: Best practices for installing dependencies - Dockerfile or ENTRYPOINT?

How to specify working directory for ENTRYPOINT in Dockerfile

Set project directory as Workdir for Entrypoint in Dockerfile

Dockerfile with entrypoint only from base image