Docker is a platform for developing, shipping, and running applications in containers.
Dockerfile
in the root directory of your project.docker build
.docker run
.# Use an official Python runtime as a parent image
FROM python:3.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["python", "app.py"]
FROM
keyword specifies the base image to use.WORKDIR
keyword sets the working directory for subsequent commands.COPY
keyword copies files from the host to the container.RUN
keyword executes a command in the container.EXPOSE
keyword exposes a port for the container.ENV
keyword sets an environment variable.CMD
keyword specifies the default command to run when the container starts.docker build
: Builds a Docker image from a Dockerfile.docker run
: Runs a Docker container from an image.docker ps
: Lists all running containers.docker stop
: Stops a running container.docker rm
: Removes a stopped container.docker rmi
: Removes an image.docker-compose
: Manages multi-container Docker applications.