How to properly override the ENTRYPOINT using docker run

Adrian Oprea
Jan 18, 2017 · 2 min read
Image for post
Image for post
kyohei itoDocker-4

Originally published on

As we all know, Docker is an amazing piece of software. I don’t want to go over its benefits. That’s for another article, coming very soon. What I do want to share with you is the way to properly override a Docker image entrypoint when using docker run.

From the official documentation:

Keep in mind the “what executable to run” part!

Many people trying to override the ENTRYPOINT at runtime, using docker runwill make mistake of passing the executable's arguments directly after it, like so (happy horizontal scrolling):

docker run --entrypoint "/bin/ls -al /root" debian

What is the problem here? Well the documentation clearly states that the ENTRYPOINT only specifies the executable to run, when the container starts.

So they get an error like below

container_linux.go:247: starting container process caused "exec: \"/usr/bin/ls -al\": stat /usr/bin/ls -al: no such file or directory"
docker: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"/usr/bin/ls -al\": stat /usr/bin/ls -al: no such file or directory".
ERRO[0001] error getting events from daemon: net/http: request canceled

There is something a bit counter-intuitive here and if you take a good look at the example commands on the documentation page, you’ll see that the arguments are being passed after the image name.

docker run -it --entrypoint /usr/bin/redis-cli example/redis --help

This means that if we want to pass the -al flags to our ls command we should write the whole thing like this:

docker run --entrypoint "/bin/ls" debian -al /root

Hope this clears things out for you and saves you a ton of headaches.

Like the article? Found it useful? Follow me on Medium / Twitter.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store