Dockerfile (Containerization contd…)
- CMD and ENTRYPOINT
- When a docker container starts it executes
- Whatever is present in entrypoint and what ever has been written in CMD will be arguments to ENTRYPOINT
- If entrypoint is present but CMD is not present in Dockerfile then whatever is written in ENTRYPOINT will be executed
- IF ENTRYPOINT is not found and ony CMD Exists then CMD will be executed
- CMD can be overriten by passing arguments after image name in docker run command

- IF We donot write entrypoint or CMD the base images entrypoint or CMD will be considered
- When a docker container starts it executes
- Your container will be in running state as long as PID1 (ENTRYPOINT + CMD) is running
- Ideally anything can go in CMD or entrypoint, But in practice we execute the commands that start our application and wait till the application is executing.
- Typical startup commands
- java:
- spring boot:
java -jar <jarfile path> - app server: if your app runs on some external server then take the base image of the app server and dont write CMD or ENTRYPOINT
- spring boot:
- react js/angular js/vue js
- first option:
npm run startor equivalent - best option is to create a html site and run in nginx
- first option:
- dotnet (asp.net core)
dotnet <dll path>
- Python
- flask
python app.pyor server based startup - django
python app.pyor server based startup - fastapi
uvicorn main:app --host 0.0.0.0 ...
- flask
- java:
Other instructions
- Refer Here for official docs for reference
- WORKDIR
- USER
Lets Build a image for Python fastapi
- Refer Here for the code
