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

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

Docker: understanding ENTRYPOINT and CMD instructions

confused with CMD and ENTRYPOINT in dockerfile

dockerfile: how use CMD or ENTRYPOINT from base image

How to specify working directory for ENTRYPOINT in Dockerfile

Docker entrypoint and cmd together

Use here document with ENTRYPOINT/CMD in Dockerfile

CMD doesn't run after ENTRYPOINT in Dockerfile

Combining ENTRYPOINT and CMD in Dockerfile targeting different executables

Dockerfile Entrypoint issue

Dockerfile with entrypoint only from base image

Dockerfile execute additional scripts in entrypoint

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

Understanding Dockerfile CMD/ENTRYPOINT

exec not found using Dockerfile ENTRYPOINT

Set project directory as Workdir for Entrypoint in Dockerfile

Dockerfile ENTRYPOINT with parameters

Access dockerfile ENV variables in entrypoint

Dockerfile CMD unable to locate entrypoint file

Not possible to override command with CMD or Entrypoint

Dcokerfile pass ENV to ENTRYPOINT or CMD

Dockerfile without CMD or Entrypoint

Dockerfile entrypoint/cmd not executing on container import

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

Entrypoint clause not working in the dockerfile

Dockerfile - exec form of ENTRYPOINT and shell form of CMD

dockerfile : npm not found at entrypoint?

Entrypoint file not being found for Dockerfile

Dockerfile ENTRYPOINT ignores WORKDIR