Careeroza
Dockerfile Instructions
Main Instructions
| Instruction | Purpose |
|---|---|
FROM | base image; every Dockerfile starts with it |
WORKDIR | working directory for the following instructions |
COPY | copy files from the build context into the image |
RUN | run a command at build time (install packages) |
ENV | set an environment variable (build and run time) |
ARG | a build-time variable (--build-arg) |
EXPOSE | documents the port the app listens on |
USER | user the container runs as |
CMD | default command when the container starts |
ENTRYPOINT | fixed executable; CMD then supplies default arguments |
HEALTHCHECK | command Docker runs to check the app is healthy |
RUN vs CMD vs ENTRYPOINT
RUNexecutes while building and its result is saved in the image.CMDis the default command at start-up;docker run image other-cmdreplaces it.ENTRYPOINTis always run; arguments fromCMDordocker runare appended.
ENTRYPOINT ["python", "manage.py"]
CMD ["runserver", "0.0.0.0:8000"]
# docker run app -> python manage.py runserver 0.0.0.0:8000
# docker run app migrate -> python manage.py migrateTip: Use the JSON (exec) form CMD ["a", "b"]: the process runs as PID 1 and receives stop signals, so containers shut down gracefully.