Home  >  Article  >  Operation and Maintenance  >  How to install docker in Linux

How to install docker in Linux

PHPz
PHPzOriginal
2023-04-25 15:55:261138browse

Docker is a very popular containerization technology that can easily create, deploy and run applications. It is widely used in development, testing and production environments. Installing Docker in a Linux system is also very simple. This article will introduce how to install Docker in different Linux distributions.

1. Ubuntu

There are many ways to install Docker in Ubuntu, the following are two of them:

  1. Install the official Docker apt package

Use the apt-get command to install the official Docker apt package:

$ sudo apt-get update

$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

$ sudo apt-get update

$ sudo apt-get install docker-ce docker-ce-cli containerd.io

The above command will download and install Docker CE and containerd.io from the official.

  1. Use the official installation script

You can also use the official installation script to install Docker:

$ curl -fsSL https://get.docker.com -o get-docker.sh

$ sudo sh get-docker.sh

The above command will be downloaded and executed from the Docker official website Install script.

2. CentOS

There are many ways to install Docker in CentOS. The following are two of them:

  1. Install the official Docker yum package

Use the yum command to install the official Docker yum package:

$ sudo yum install -y yum-utils

$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

$ sudo yum install docker-ce docker-ce-cli containerd.io

The above command will download and install Docker CE and containerd.io from the official.

  1. Use the official installation script

You can also use the official installation script to install Docker:

$ curl -fsSL https://get.docker.com -o get-docker.sh

$ sudo sh get-docker.sh

The above command will be downloaded and executed from the Docker official website Install script.

3. Other Linux distributions

In addition to Ubuntu and CentOS, the methods of installing Docker in other Linux distributions are similar. You can download the corresponding installation package or script from the Docker official website and install it.

4. Configuring Docker

After installing Docker, you still need to perform related configurations for normal use. The following are some common configurations:

  1. Start Docker

In Ubuntu, use the following command to start Docker:

$ sudo systemctl start docker

In CentOS, use the following Command to start Docker:

$ sudo systemctl start docker
  1. Set Docker to start automatically at boot

In Ubuntu, use the following command to set Docker to start automatically at boot:

$ sudo systemctl enable docker

In CentOS , use the following command to set Docker to start automatically at boot:

$ sudo systemctl enable docker
  1. Using Docker

After installing Docker, you can use the following command to verify whether the installation is successful:

$ sudo docker run hello-world

This command will download the hello-world image officially provided by Docker and start a container to run it.

Summary

Docker is a very popular containerization technology that makes it easy to create, deploy, and run applications. Installing Docker in a Linux system is also very simple. You only need to download the installation package or script and configure it accordingly. After installation, you can use Docker to create and manage containers with simple commands.

The above is the detailed content of How to install docker in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn