Docker - Entrypoint (Main)

About

Language - (Main|Application Entry point) in Docker.

The entry point script is the script called when creating a container from an image with the docker run command

The entrypoint is specified in a dockerfile.

Management

Assignement

Console

docker run --entrypoint /script.sh repo/image

where: Docker - docker run (Creating a container)

Default (dockerfile)

The default entrypoint is specified in the dockerfile. See Doc entrypoint

It has two different behavior that depends of the assignment format. ENTRYPOINT has the following forms:

# exec form, preferred
ENTRYPOINT ["executable", "param1", "param2"] 
# or shell form
ENTRYPOINT command param1 param2 
# or
ENTRYPOINT ["python"]
CMD ["myPythonFile.py"]

If you want to get the parameters from the command line passed to the entry point, you need to choose the exec form

Exec form

Command line arguments to docker run will be appended after all elements in an exec form ENTRYPOINT, and will override all elements specified using CMD.

Shell form

The shell form prevents any command line arguments (cmd or via run) from being used.

The ENTRYPOINT will be started as a subcommand of /bin/sh -c, which does not pass signals. This means that the executable will not be the container’s PID 1 - and will not receive Unix signals - so your executable will not receive a SIGTERM from docker stop <container>.

List

docker inspect --format "{{range .Config.Entrypoint}}{{.}}{{end}}" containerName

See Docker - Inspect

Example

Default

When you run docker like this:

docker run -i -t ubuntu bash 

Wrapper entrypoint.sh

The below script start a process before starting the command given at the command line.

It's a wrapper around the default entrypoint.

If you set the entrypoint in your dockerfile, you need to set it with the exec form otherwise you get no arguments.

#!/usr/bin/env bash

echo Starting the ssh-agent for convenience
eval `ssh-agent`

# Start the passed command ($*)
/bin/sh -c "$*"

Powered by ComboStrap