DevOps is a set of practices that combines software development (Dev) and IT operations (Ops). The main goal is to shorten the systems development life cycle and provide continuous delivery with high software quality.
Docker is a platform that enables developers to automate the deployment of applications inside lightweight, portable containers. Containers package an application and its dependencies, ensuring consistency across different environments.
docker run
: Create and start a container.docker ps
: List running containers.docker stop
: Stop a running container.docker build
: Build a Docker image from a Dockerfile.docker-compose up
: Start all services defined in a docker-compose.yml
file.
docker images
: List all Docker images.docker rmi
: Remove a Docker image.docker pull
: Download a Docker image from a registry.docker exec
: Execute a command in a running container.
docker rm
: Remove a stopped container.docker inspect
: View detailed information about a container or image.docker network ls
: List all Docker networks.docker volume ls
: List all Docker volumes.docker start
: Start a stopped container.docker restart
: Restart a running or stopped container.docker logs
: View the logs of a container.docker network
: Manage Docker networks.
docker run -it <image>
to run a container interactively, allowing you to access the terminal.docker run -d <image>
to run a container in the background, allowing it to run independently of the terminal.A Dockerfile is a text file that contains instructions for building a Docker image. It defines the environment in which an application runs, including the base image, dependencies, and configuration.
A base image is the starting point for building a Docker image. It can be an official image from Docker Hub or a custom image. Base images provide the necessary environment and libraries for your application to run.
Multi-stage builds allow you to create smaller, more efficient Docker images by separating the build environment from the runtime environment. This reduces the final image size by excluding unnecessary build dependencies.
# Use an official base image
FROM <base_image>
# Set the working directory
WORKDIR /app
# Copy files from the host to the container
COPY . .
# Install dependencies
RUN pip install -r requirements.txt
# Expose a port
EXPOSE 5000
# Define the command to run the application
CMD ["python", "app.py"]
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "app.py"]
version: '3'
services:
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/app
db:
image: postgres:latest
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: password