Docker, docker-compose installation and use

Docker is an open source containerization platform that allows developers to easily package applications and quickly deploy them on any platform. Docker Compose is a tool officially provided by Docker to manage the construction, start and stop of multiple containers.

The following are the installation, common command explanation and usage examples of Docker and Docker Compose:

Step 1: To install Docker,
please refer to the official documentation or follow the steps below to install Docker:

  1. To update the package manager on a Linux system:
sudo apt-get update
  1. Install some necessary dependencies:
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
  1. Add the official Docker GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  1. Add the Docker repository:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  1. Install Docker CE:
sudo apt-get update
sudo apt-get install docker-ce
  1. Verify that Docker is installed correctly:
sudo docker run hello-world

Step 2: Install Docker Compose

Please refer to the official documentation or follow the steps below to install Docker Compose:

  1. Download the latest version of the Docker Compose binary from the official Docker website.

  2. Copy the downloaded binaries into the /usr/local/bin directory:

sudo cp docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
  1. Grant docker-compose executable permissions:
sudo chmod +x /usr/local/bin/docker-compose
  1. Verify that docker-compose is installed correctly:
docker-compose --version

Docker common commands:

  • docker build: build image using Dockerfile
  • docker run: run the image to create a container
  • docker ps: Display a list of running containers
  • docker stop: Stop the container
  • docker rm: delete container
  • docker images: Display a list of local mirrors
  • docker rmi: delete mirror

Common commands for Docker Compose:

  • docker-compose up: create and start all containers
  • docker-compose down: stop and remove all containers, networks and volumes
  • docker-compose start: start the service
  • docker-compose stop:Out of service
  • docker-compose restart: restart the service
  • docker-compose logs: View log output

Here is a simple Docker Compose orchestration example:

version: '3'

services:
  web:
    build: .
    ports:
     - "5000:5000"
  redis:
    image: "redis:alpine"

This file defines two services: web and redis. The web service is built using the Dockerfile in the current directory and maps it to port 5000 on the host machine. The Redis service uses the redis:alpine image on Docker Hub.

To use this file, run the following command in the directory containing the file:

docker-compose up -d

This command will create and start all services. To stop the service and remove all containers, run the following command:

docker-compose down

Output format: The output format of Docker and Docker Compose is similar, usually one or more lines of text output, which contains information about containers, images, and networks. Various options and filters can be used to adjust the output to suit different needs. In practical applications, it is often necessary to save the output to a log file for later analysis and processing.

The output format of Docker and Docker Compose is similar, usually one or more lines of text output, which contains information about containers, images, and networks. Various options and filters can be used to adjust the output to suit different needs. In practical applications, it is often necessary to save the output to a log file for later analysis and processing.

In addition to basic commands and options, Docker also provides some advanced features and configuration options, such as Docker Swarm and Docker Registry. Docker Swarm is a tool for managing multiple Docker hosts. It can automatically deploy containers to different hosts and provide load balancing and failover functions. Docker Registry is a server for managing Docker images, which allows users to easily store, share and pull Docker images.

In summary, Docker is a powerful containerization platform that helps developers create, build, and deploy applications with ease. Docker Compose is a simple but effective tool that helps users manage and orchestrate multiple containers. At the same time, Docker also provides many advanced features and configuration options, making it suitable for different scenarios and applications.

Guess you like

Origin blog.csdn.net/m0_50758217/article/details/130370712