When a docker container kicks off the ENTRYPOINT instruction is run, and the commands/arguments from the CMD instruction are passed to it as arguments.
Executable Pattern
When you want the docker container to act like an executable you can use CMD to pass arguments to the ENTRYPOINT. Below is an example that will fetch data from the Irish Single Electricty Market website.
Here’s the dockerfile called entrypoint_cmd.docker. Note that there is no CMD instruction because it will be specified when we run the container.
And here is main.py.
First build the image using docker build -t semo_image -f "./entrypoint_cmd.docker" .. Then run the container to get data from a specific half hour with docker run -t --rm semo_image "202402241030". Any additional arguments provided overwrite the CMD instruction in the Dockerfile (if there are any), so in this case "202402241030" is passed to the ENTRYPOINT script. Here’s the output:
If no CMD argument is specified, i.e. docker run -t --rm semo_image, then this little example is setup to get the data from 2 hours ago.
Setup Pattern
Another typical pattern seems to be using the ENTRYPOINT script to carry out setup that is required before the CMD commands are run. For an example see this mysql Dockerfile where the ENTRYPOINT does lots of setup and then the last command is exec "$@" which will exec the CMD arguments that are passed to the ENTRYPOINT.
Documented
Unsurprisingly this is all very well documented but great to put together a little example nonetheless.
This site uses cookies for things like Google Analytics.
More information is in the Privacy Policy which you can view now
by clicking the cookie or later using the link at the bottom of the page.