Set a Docker Container Application Entrypoint

This post will show how to set a Docker container to start an application or command on startup using a Dockerfile.

EntryPoint

The Docker ENTRYPOINT statement allows us to turn a Docker container into an executable program and run a specific script, app or command every time the container is run.

In the following Dockerfile example, I build a PowerShell Docker image that runs the $pstableversion command every time I deploy a container from the image.

FROM ubuntu 
LABEL version="v1.0"
ENV builddir=build
RUN mkdir \${builddir}
RUN apt-get update
RUN apt-get install -y wget apt-transport-https software-properties-common
RUN wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN apt-get update
RUN add-apt-repository universe
RUN apt-get install -y powershell
ENTRYPOINT ["pwsh", "-command" ,"$psversiontable"]
 

In the below example, I am running a Python script when the container starts. The entrypoint statement uses Python3 to run the script (script.py)

FROM ubuntu
RUN apt update
RUN apt install -y python3-pip 
ADD script.py /
ENTRYPOINT ["python3" , "script.py"]

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.