Running Docker Containers - BKJackson/BKJackson_Wiki GitHub Wiki
With the entrypoint and docker run commands.
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
Use capital letters for ENTRYPOINT.
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"]
COPY ./docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["postgres"]
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;
Note: Use lowercase letters.
entrypoint: /code/entrypoint.sh
entrypoint:
- php
- -d
- zend_extension=/usr/local/lib/php/xdebug.so
- -d
- memory_limit=-1
- vendor/bin/phpunit
docker run --entrypoint
docker-compose run --entrypoint