Docker Community Forums

Share and learn in the Docker community.

Conditional entrypoint for containers

(Atemiz) #1

I want to create two containers from one image. First container will be based on one server (ie. bokeh)
The second one will based on other server (ie Flask) .

How can I form the command lines with entrypoints for creating of two containers ?
Is there any other way you can recommend?


(David Maze) #2

Best option: build two images. Especially if they’re running different applications; but even if not, you can write a minimal Dockerfile that’s just

FROM my-image-that-has-the-code
CMD ["the_flask_app"]

Second option: just provide the command to run on the docker run command line (or explicitly in your docker-compose.yml, Kubernetes pod spec, Nomad job spec, …).

docker run ... my-image the_flask_app

Related recommendation: don’t put an ENTRYPOINT in your Dockerfile unless you mean it. Use CMD instead. (ENTRYPOINT makes that last command and the useful docker run --rm -it my-image sh harder to type. You want it for a script that does startup-time setup that ends in exec "$@" and so also runs the CMD; and for extremely minimal containers that only have statically-linked binaries and no shell, where running any other command is actually impossible.)