Running Docker Containers - BKJackson/BKJackson_Wiki GitHub Wiki

With the entrypoint and docker run commands.

Docker Entrypoint

Entrypoint sets the command and parameters that will be executed first when a container is run.
Any command line arguments passed to docker run <image> will be appended to the entrypoint command, and will override all elements specified using CMD. How to use Entrypoint with Docker and Docker Compose

Dockerfile ENTRYPOINT instruction syntax:

Use capital letters for ENTRYPOINT.

If you need shell processing features, use:

But note that this prevents any CMD or run command line arguments from being used. Also, since sh -c does not pass signals, the executable will not be the container's PID 1 and so will not receive Unix signals such as a SIGTERM from docker stop .

ENTRYPOINT ["sh", "-c", "echo $HOME"]  

Calling an entrypoint script from Dockerfile

COPY ./docker-entrypoint.sh /  
ENTRYPOINT ["/docker-entrypoint.sh"]  
CMD ["postgres"]  

Simple entrypoint example that returns a value

Simple Dockerfile:

FROM mcr.microsoft.com/dotnet/core/runtime:3.0-alpine

ENTRYPOINT ["echo"] 

Small bash script that builds the container, runs it with argument 42 and verifies that the output is the same as the input:

#!/usr/bin/env bash
docker build -t hjerpbakk/example .

ARGUMENT="42"
RESULT=$(docker run --rm hjerpbakk/example "$ARGUMENT")

if [ "$RESULT" = "$ARGUMENT" ]; then
   echo "container ran successfully";
   exit;
fi

echo "container failed. Expected:"
echo "$ARGUMENT"
echo "but got:"
echo "$RESULT"
exit 1;

Docker Compose entrypoint (docker-compose.yml)

Note: Use lowercase letters.

entrypoint: /code/entrypoint.sh  

entrypoint lists in docker-compose.yml

entrypoint:
    - php
    - -d
    - zend_extension=/usr/local/lib/php/xdebug.so
    - -d
    - memory_limit=-1
    - vendor/bin/phpunit  

override entrypoint instructions at runtime with the --entrypoint flag

docker run --entrypoint  

docker-compose run --entrypoint  
⚠️ **GitHub.com Fallback** ⚠️