Container42 Stuff I find interesting

Twitter GitHub

Docker Quicktip #1: Entrypoint

The first tip is aptly named "Entrypoint". In this tips I kind of expect that you've played around with Docker a bit, probably even have some containers running for your dev environment. So, in short, if you haven't played yet, go play and come back!

Entrypoint is great. It's pretty much like CMD but essentially let's you use re-purpose CMD as runtime arguments to ENTRYPOINT. For example...

Instead of:

docker run -i -t -rm busybox /bin/echo foo

You can do:

docker run -i -t -rm -entrypoint /bin/echo busybox foo

This sets the entrypoint, or the command that is executed when the container starts, to call /bin/echo, and then passes "foo" as an argument to /bin/echo.

Or you can do, in a Dockerfile:

FROM busybox

ENTRYPOINT ["/bin/echo", "foo"]
docker build -rm -t me/echo .
docker run -i -t -rm me/echo bar

This passes bar as an additional argument into /bin/echo foo, resulting in /bin/echo foo bar

Why would you want this? You can think of it as turning CMD into a set of optional arguments for running the container. You can use it to make the container much more versatile. This will lead into the next tip "Exec it"