Location>code7788 >text

ubuntu 22.04 install docker

Popularity:15 ℃/2025-04-04 18:03:35

1. Installation

Update package index:

sudo apt-get update

 

Allow APT to use HTTPS:

sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common

 

Add Docker official GPG key:

curl -fsSL https:///linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/

 

Add a stable version of Docker repository:

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/] /linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt// > /dev/null

 

Update the package index again:

sudo apt-get update

 

Install Docker CE (Community Edition):

sudo apt-get install -y docker-ce

View version

# docker info
Client: Docker Engine - Community
 Version:    28.0.4
 Context:    default
 Debug Mode: false
...

 

2. Modify the configuration

Create a docker data directory

mkdir -p /data/docker

 

Create a file

vi /etc/docker/

The content is as follows:

{
    "registry-mirrors": [
        "https://docker.",
        ""
    ],
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "50m",
        "max-file": "3"
    },
    "data-root": "/data/docker",
    "insecure-registries": [""]
}

Parameter explanation:

registry-mirrors: Configure the mirror accelerator to speed up the image pulling speed.Since the dockerhub image cannot be downloaded directly, a domestic accelerator is provided here, which can be downloaded directly, which is very convenient.
log-driver and log-opts: Control the storage and management of container logs.This is very necessary. Docker will generate a large number of logs after running for a long time, resulting in full disk.
data-root: Changes the storage path of Docker data.The main purpose is to change the directory to the directory where the data disk is located, because that hard disk has a large space.
insecure-registries: Allows connections to unsafe registries.Mainly configure private repositories, such as: harbor

 

Restart docker

systemctl restart docker

 

Set up the power-on self-start

systemctl enable docker

 

Test download dockerhub image

docker pull nginx:latest

It can be downloaded successfully, which means that the accelerator is set up.