Docker and Docker Compose Installation Guide

Docker is an open source containerization platform that helps us quickly build, package and run applications. Docker Compose is a tool for managing multiple container applications. It can easily define and manage the relationship between multiple containers. Now, let's start the installation process!

docker installation

apt installation
  1. sudo apt update

  2. sudo apt install docker.io

  3. sudo systemctl status docker

Configure image acceleration

vim /etc/docker/daemon.json

{
    
    
  "registry-mirrors": ["https://registry.docker-cn.com","https://hmdsd139.mirror.aliyuncs.com","https://docker.mirrors.ustc.edu.cn"],
  "log-driver":"json-file",
  "log-opts": {
    
    "max-size":"500m", "max-file":"3","compress": "true"}
}

Restart the docker daemon

systemctl daemon-reload

systemctl restart docker

docker-compose description and installation

docker-compose overview

The Compose project is Docker's official open source project, responsible for realizing the rapid orchestration of Docker container clusters. Using the Dockerfile introduced earlier we can easily define a separate application container. However, in daily development work, we often encounter situations where multiple containers need to cooperate with each other to complete a certain task. For example, to implement a Web project, in addition to the Web service container itself, it is often necessary to add a back-end database service container; for another example, distributed applications generally include several services, and each service generally deploys multiple instances. If each service has to be started and stopped manually, the efficiency will be low and the amount of maintenance will be heavy. At this time, a tool is needed that can manage a set of associated application containers, which is Docker Compose.

Important concepts of Compose
  • Project: A complete business unit consisting of a set of associated application containers, defined in the docker-compose.yml file.
  • Service: An application container can actually include several container instances running the same image.

All yml files in the docker compose running directory form a project. A project contains multiple services. Each service defines the image, parameters, and dependencies of the container running. A service can include multiple container instances. docker-compose is an orchestration tool for docker containers, which mainly solves the management of multiple containers that are dependent on each other.

docker-compose installation

Download the docker-compose binary file from github and install it

https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-linux-x86_64

  • Add executable permissions
cd /usr/local/bin/
mv docker-compose-linux-x86_64 docker-compose
sudo chmod +x docker-compose
  • Test the installation results
    docker-compose --version

Docker Compose version v2.5.0

Frequently asked questions when using docker

Error when downloading Alibaba Cloud image in Docker

error message

Error response from daemon: manifest for registry.cn-hangzhou.aliyuncs.com/mindoc/mindoc:v0.12 not found: manifest unknown: manifest unknown

  1. Check network connection: Make sure your server can connect to the Internet properly. Try using a browser or other tool to test the server's network connection.

  2. Check Docker configuration: Check your Docker configuration file (usually /etc/docker/daemon.json) to confirm whether the correct image accelerator address is configured. Alibaba Cloud provides the accelerator address, and you can find the corresponding documentation on the Alibaba Cloud official website.

  3. Restart the Docker service: After modifying the Docker configuration file, you need to restart the Docker service for the configuration to take effect. Docker can be restarted using the following command:

sudo systemctl restart docker
  1. Clear cache: Sometimes Docker's cache may cause problems. Try clearing Docker's cache and re-downloading the image. The cache can be cleared using the following command:
docker system prune -a
  1. Use other mirror sources: If the above method still cannot solve the problem, you can try to use other reliable mirror sources, such as Huawei Cloud, NetEase Cloud, etc. Choose the appropriate mirror source based on your needs and configure it according to the documentation they provide.

Guess you like

Origin blog.csdn.net/weixin_44002151/article/details/132591784