Docker - Entrypoint (Main)

> Virtualization - (Virtual Machine|Container) > Docker

1 - 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.

Advertising

3 - Management

3.1 - Assignement

3.1.1 - Console

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

where: Docker - docker run (Creating a container)

3.1.2 - 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
ENTRYPOINT command param1 param2 (shell form)
# 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

3.1.2.1 - 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.

3.1.2.2 - 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>.

Advertising

3.2 - List

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

See Docker - Inspect

4 - Example

4.1 - Default

When you run docker like this:

docker run -i -t ubuntu bash 

4.2 - 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.

entrypoint.sh
#!/usr/bin/env bash
 
echo Starting the ssh-agent for convenience
eval `ssh-agent`
 
# Start the passed command ($*)
/bin/sh -c "$*"
Advertising