Install and deploy docker in Linux

what is docker

Docker is an open source containerization platform that helps developers build, package, distribute and run applications more easily. It is based on containerization technology and uses operating system-level virtualization to isolate applications and the environments they depend on. By using Docker, developers can quickly deploy and scale applications on different hosts without worrying about environment configuration and dependencies.

Traditional applications run on top of the operating system and are directly dependent on the operating system and hardware. In this case, when the application needs to be deployed on more machines, the environment needs to be reconfigured and problems caused by differences in operating systems and hardware need to be solved. Docker uses a containerization method to package the application and its dependent environment into an independent container. This container has its own file system, virtual network interface, and process space, isolated from other containers and the host.

Docker features and benefits include:

  1. Flexibility and portability: Docker containers package applications and dependencies in a standardized way so that they can be deployed and run in different environments without reconfiguration.

  2. Lightweight and high-performance: Because Docker containers share the operating system kernel, containers are more lightweight and high-performance than virtual machines. They start and stop faster.

  3. Scalability: With Docker, containers can be easily created and managed on multiple hosts to achieve horizontal expansion and load balancing of applications.

  4. Highly customizable: Docker provides a flexible way to build images and containers. You can customize container configurations, manage and share custom images as needed.

  5. Ecosystem and resource sharing: Docker Hub is an official container image repository where developers can share their own images or obtain existing images from others. This saves development time and resources.

System environment requirements

To install docker, the system environment needs to meet the following requirements:
Operating system version: Docker is suitable for a variety of Linux distributions, such as Ubuntu, CentOS, etc. Here I am using CentOS.

Kernel version: Docker requires running on Linux kernel 3.10 or higher. You can check your kernel version with the following command:

uname -r

Install and use docker

Before installing docker, we need to install the necessary management tools first

  1. First install the necessary management tools, use Linux terminal commands, and install the used software packages and tools.
sudo yum install -y yum-utils device-mapper-persistent-data lvm2

This command is used to install some software packages and tools. Explain the role of each component:

  • yum-utils: is a Yum extension toolset that provides some additional commands and functions for managing and maintaining the Yum package manager.

  • device-mapper-persistent-data: It is the persistence data package of the Linux device mapper, which provides the persistence function of the device mapper.

  • lvm2: is a software package for Logical Volume Manager (LVM) that provides a set of tools for creating, extending, and managing logical volumes and volume groups.

  • -yThe parameter is used to automatically answer "yes" to all questions during the installation process, thereby avoiding the need for manual confirmation during the installation process. In this way, the entire command will automatically install the specified packages and tools.
    Insert image description here

  1. To add Docker warehouse configuration through Yum, use the following command
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

This line of code is a command used to configure Yum. It will add a new warehouse configuration file to /etc/yum.repos.d/the directory to download and install the Docker software through Yum. The meaning of each part:

  • sudo: sudois a Linux command that allows ordinary users to execute privileged commands as superuser.
  • yum-config-manager: This command is used to configure related settings of the Yum package manager.
  • --add-repo: This option tells yum-config-managerthe command to add a new repository.
  • https://download.docker.com/linux/centos/docker-ce.repo: This parameter specifies the URL of a remote repository, which is the official software repository of Docker CE (Community Edition) on CentOS systems.

When we execute this command, it will download and add a docker-ce.repowarehouse configuration file named to /etc/yum.repos.d/the directory. In this way, we can use Yum to install and update Docker software.
Insert image description here
When you see the following code, it means that the Docker warehouse configuration has been added successfully.

grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

The meaning of these two lines is that after executing the previous command sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo, a file named was downloaded from the specified URL docker-ce.repoand saved to /etc/yum.repos.d/the directory.

  • The first line grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repois a notification message indicating that a file is being downloaded from the specified URL and saved to the specified path.

  • The second line repo saved to /etc/yum.repos.d/docker-ce.repois a confirmation message indicating that the warehouse configuration file has been successfully saved to /etc/yum.repos.d/docker-ce.repothe path.

This process means that the configuration file of the Docker software warehouse has been downloaded normally and saved to the specified location, and you can continue to use Yum to manage and install Docker software packages.

  1. Install Docker CE (Community Edition) software through sudo yum install -y docker-ce docker-ce-cli
sudo yum install -y docker-ce docker-ce-cli

This line of code uses the Yum command to install the Docker CE (Community Edition) software.

  • sudo: sudois a Linux command that allows ordinary users to execute privileged commands as superuser.
  • yum install: This is the command of the Yum package manager, used to install software packages.
  • -y: This is an option that automatically answers all prompts during installation without manual confirmation.
  • docker-ce docker-ce-cli: This is the name of the package to install. docker-ceIt is the main component of the Docker CE software and docker-ce-cliis the command line tool used to interact with Docker.

When we execute this command, Yum will automatically download the relevant software packages from the Docker CE software repository, and then install Docker CE and Docker CE CLI to your system. During the installation process, we do not need to manually confirm any prompts, Yum will handle it automatically.
Insert image description here
4. After the installation is complete, start Docker and set it to start automatically at boot.

sudo systemctl start docker
sudo systemctl enable docker

The above two lines of code are commands to use the systemctl command to operate the Docker service.

  • sudo systemctl start docker: This command is used to start the Docker service to start running and managing Docker containers.
  • sudo systemctl enable docker: This command is used to set the Docker service to start at boot, ensuring that Docker is automatically started after the system is restarted.

After executing these two commands, the Docker service will start and will also start automatically after the system restarts. In this way, we can use Docker containers in the system.

After executing sudo systemctl enable dockerthe command, the following code is returned

Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

This output indicates that a symbolic link was successfully created /usr/lib/systemd/system/docker.servicelinking the file to /etc/systemd/system/multi-user.target.wants/docker.service.

In the system, /etc/systemd/system/multi-user.target.wants/the directory contains all system services that need to be started in multi-user mode. By creating a symbolic link, that is, adding the path to the configuration file of the Docker service to the directory, you can automatically start the Docker service when the system starts.

sudo systemctl enable dockerThis is usually the output after executing the command, indicating that the Docker service has been successfully set to start at boot.

  1. Verify whether Docker is installed successfully. Enter and you docker --version
    Insert image description here
    can see the version number, which means Docker is installed successfully.
  2. Upgrade Docker engine
sudo yum -y upgrade docker

The meaning of this line of code is to upgrade the Docker software package with root privileges through the yum command.

  • sudo: Execute subsequent commands with root (superuser) permissions. The current user's password is required to confirm permissions.
  • yum: It is a package manager used to install, upgrade and delete software packages in RPM (Red Hat Package Manager)-based Linux distributions.
  • -y: When running the yum command, automatically answer all prompts and confirmation messages with "yes" to automatically perform installation and upgrade operations, avoiding the need for manual confirmation.
  • upgrade: Use the yum command to upgrade software packages.
  • docker: Specify the name of the software package to be upgraded, here it is Docker.

Please note that before executing this command, we need to ensure that the Docker engine repository has been correctly set up and enabled.

  1. Install docker-compose
 curl -L https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-linux-x86_64 -o /usr/bin/docker-compose

This command downloads the Docker Compose binary and saves it to /usr/bin/docker-composethis path.

  • curl -L: Use curlthe command to download, and -Lthe parameter indicates that you want to follow the redirection.
  • https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-linux-x86_64: Download URL, which is the download link for the Linux x86_64 binary of Docker Compose version 2.18.1.
  • -o /usr/bin/docker-compose: -oThe parameter specifies the downloaded file saving path /usr/bin/docker-compose.

This command will download the Docker Compose binary from the specified URL and save it in /usr/bin/docker-composethis location. Before running this command, we need to have sufficient permissions to write to the directory.

8. Enter the following path:

cd /usr/bin/
  1. Set /usr/bin/docker-composeas executable:
sudo chmod +x /usr/bin/docker-compose

This command will give /usr/bin/docker-composethe file execute permissions, allowing us to run the file directly in the terminal. Here we need to make sure we have sufficient permissions to execute this command.

  1. Query the docker-compose installation version:
docker-compose -v

Insert image description here
At this point, we have completed the installation and configuration of the dock.

Guess you like

Origin blog.csdn.net/w137160164/article/details/131405184
Recommended