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.

Frequently asked questions

How does Docker handle entry point?
This task is covered in 2 stacks on this page: Docker, Python. The "ENTRYPOINT - Fixed Container Executable" snippet in Docker uses `ENTRYPOINT ["executable", "arg1"]`.
Which command does the Docker example use?
The "ENTRYPOINT - Fixed Container Executable" snippet uses `ENTRYPOINT ["executable", "arg1"]`, from the Dockerfile section of the Docker cheat sheet.
Which stacks cover "entry point" on this page?
Docker, Python. Together they hold 2 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "ENTRYPOINT - Fixed Container Executable": 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.