DOCKERFILE SYNTAX
FROM - Used to get parent image/base image. In the case of Python-based website projects we use
python:3.8-slim-buster.
WORKDIR - Used to set the working directory and any subsequent commands in the Dockerfile will be executed from within that directory.
when we setWORKDIR /app
then any subsequent commands in the Dockerfile will be executed from within the /app directory.
COPY - used to copy files or directories from the host machine to the container's file system.
COPY . /app
Here, we're using the COPY instruction to copy all the contents of the current directory (the directory where the Dockerfile is located) to the /app directory inside the container.
RUN - used to execute commands inside the container during the image build process. When we use Flask then,
RUN pip install -r requirements.txt
The requirements.txt file lists the required Python packages for the Flask application to run.
EXPOSE - In this case, the Flask web application runs on port 80 inside the Docker container. By using the EXPOSE instruction in the Dockerfile, we are informing Docker that the container will listen on port 80 and that this port should be exposed to the outside world.
ENV - used to define an environment variable in the Docker container. Here we have used,
ENV NAME world
By setting the NAME environment variable in the Dockerfile, we can customize the message displayed by the Flask application running inside the Docker container, without needing to modify the application code.
CMD - is used to specify the default command that will be run when the container launches. When a Docker container starts up, it runs a single command by default. This command can be specified in the Dockerfile using either the CMD or ENTRYPOINT instructions.
RUN python run
app.py
In this case, we are using the CMD instruction to specify that the default command to run is the Python interpreter, with the argument app.py.
Note that the CMD instruction can be overridden by passing a different command to the docker run command.