Entry point

2 snippets across 2 stacks — Docker, Python

DKDocker

ENTRYPOINT — Fixed Container Executable

DK · Dockerfile
syntax
ENTRYPOINT ["executable", "arg1"]
ENTRYPOINT command arg1
example
ENTRYPOINT ["python", "manage.py"]
CMD ["runserver", "0.0.0.0:8000"]

Note ENTRYPOINT sets the main executable. CMD then provides default arguments that users can override. Together: ENTRYPOINT ["python", "manage.py"] + CMD ["runserver"] means the user can run docker run myapp migrate to swap the subcommand.

PYPython

__name__ == '__main__' Guard

PY · Modules & Imports
syntax
if __name__ == '__main__':
    ...
example
# my_module.py
def compute_tax(price: float, rate: float = 0.08) -> float:
    return price * rate

if __name__ == "__main__":
    # Only runs when executed directly, not when imported
    result = compute_tax(100)
    print(f"Tax: ${result:.2f}")
output
Tax: $8.00

Note This guard prevents code from running when the module is imported by another file. Essential for reusable modules that also serve as scripts.