Table of Contents

What is the Entrypoint (Main) in Docker?

About

This page is about the main entry in Docker.

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

When the entry point program exits, the VM is stopped (killed). A process needs to run in the foreground.

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 "$*"

Entrypoint vs Cmd

In the below excerpt of a Dockerfile, you can see the difference between:

A dockerfile for Curl

# Set the entrypoint to curl
ENTRYPOINT ["curl"]

# Default argument
CMD ["https://www.example.com"]

Management

Assignement

Console

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

where: How to run a docker image with example to create a container?

Overwrite / Reset

In a utility image where the entrypoint is the utility, you can still explorer the image by overriding it with the default.

Example with rclone

docker run -ti  --entrypoint /bin/sh rclone/rclone:1.67.0

Default (dockerfile)

The default entrypoint is defined by the ENTRYPOINT instruction.

List

docker inspect --format "{{range .Config.Entrypoint}}{{.}}{{end}}" (containerName|imageName)

Example on the image org/ubuntu:latest

docker inspect --format "{{range .Config.Entrypoint}}{{.}}{{end}}" org/ubuntu:latest

See Docker - Inspect

Multiple processes

How to start multiple processes in Docker?