Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
••••••••••••••••••••
Intelligence View
⚡ tsecurity.de Intelligence

Dockerfile: CMD vs ENTRYPOINT

CMD and ENTRYPOINT commands in Dockerfile can get confusing if not tried by actually executing it. Show, don't tell 1. CMD By default docker images like ubuntu…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!

CMD and ENTRYPOINT commands in Dockerfile can get confusing if not tried by actually executing it.






Show, don't tell






1. CMD




  • By default docker images like ubuntu have CMD as last command in its dockerfile as below:

    CMD ["/bin/bash"]


  • When we run docker container with below commands




docker run --rm --name cmd ubuntu:latest ls /home



or



docker run --rm --name cmd ubuntu:latest date



Default command gets overridden by what we pass as arguments, in this cases as "ls /home" and "date"




  • Above docker runs produces below outputs respectively:




~  % docker run --rm --name cmd ubuntu:latest ls -l /home/ubuntu
total 0









~  % docker run --rm --name cmd ubuntu:latest date
Sat Dec 13 16:22:53 UTC 2025









2. ENTRYPOINT




  • Let's create a docker image (entrypoint:1.0.0) with ENTRYPOINT command




FROM ubuntu:latest
WORKDIR /app
COPY script.sh .
RUN ["chmod","+x","script.sh"]
ENTRYPOINT ["/app/script.sh"]
CMD ["world"]






script.sh




#!/bin/bash
echo "Hello $1"







  • Above script expects a single argument

  • If we don't pass any argument, the default argument will be the one provided in CMD




% docker run --rm --name entrypoint entrypoint:1.0.0
Hello world







  1. If we pass an argument during a docker run then




% docker run --rm --name entrypoint entrypoint:1.0.0 december
Hello december







Learnings:




  • We can always override the CMD

  • We cannot override ENTRYPOINT, but we can override the arguments passed to the ENTRYPOINT using CMD as last command during image creation

  • ENTRYPOINT or CMD depends on usecase


Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Dockerfile: CMD vs ENTRYPOINT

Thematisch verwandte Begriffe: Dockerfile, ENTRYPOINT · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag