在Ubuntu中安装docker

环境:Ubuntu 20.04
目的:安装docker、启动服务
依据: 官方文档

一、安装

1、检查环境

1.1 卸载旧版docker

sudo su
apt remove docker docker-engine docker.io containerd runc

1.2 查看系统环境

输入命令

lsb_release -a

打印返回

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.6 LTS
Release:        20.04
Codename:       focal

2、安装依赖

apt -y install ca-certificates curl gnupg lsb-release

3、添加密钥

输入命令

curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

打印返回(返回OK即为成功)

OK

4、添加Docker软件源

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

5、安装docker

apt -y install docker-ce docker-ce-cli containerd.io

6、启动docker

systemctl start docker

7、查看docker状态

输入命令

systemctl status docker

打印返回

● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2023-11-29 19:21:17 PST; 1min 51s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 58743 (dockerd)
      Tasks: 10
     Memory: 24.9M
     CGroup: /system.slice/docker.service
             └─58743 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Nov 29 19:21:16 vac-virtual-machine systemd[1]: Starting Docker Application Container Engine...
Nov 29 19:21:16 vac-virtual-machine dockerd[58743]: time="2023-11-29T19:21:16.897970864-08:00" level=info msg="Starting up"
Nov 29 19:21:16 vac-virtual-machine dockerd[58743]: time="2023-11-29T19:21:16.899753412-08:00" level=info msg="detected 127.0.0.53 nameserver, assuming systemd-resolved, >
Nov 29 19:21:17 vac-virtual-machine dockerd[58743]: time="2023-11-29T19:21:17.036608569-08:00" level=info msg="Loading containers: start."
Nov 29 19:21:17 vac-virtual-machine dockerd[58743]: time="2023-11-29T19:21:17.497580306-08:00" level=info msg="Loading containers: done."
Nov 29 19:21:17 vac-virtual-machine dockerd[58743]: time="2023-11-29T19:21:17.566831721-08:00" level=info msg="Docker daemon" commit=311b9ff graphdriver=overlay2 version=>
Nov 29 19:21:17 vac-virtual-machine dockerd[58743]: time="2023-11-29T19:21:17.567026727-08:00" level=info msg="Daemon has completed initialization"
Nov 29 19:21:17 vac-virtual-machine systemd[1]: Started Docker Application Container Engine.
Nov 29 19:21:17 vac-virtual-machine dockerd[58743]: time="2023-11-29T19:21:17.636911780-08:00" level=info msg="API listen on /run/docker.sock"

8、查看版本

输入命令

docker version

打印返回

Client: Docker Engine - Community
 Version:           24.0.7
 API version:       1.43
 Go version:        go1.20.10
 Git commit:        afdd53b
 Built:             Thu Oct 26 09:08:01 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.7
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.10
  Git commit:       311b9ff
  Built:            Thu Oct 26 09:08:01 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.25
  GitCommit:        d8f198a4ed8892c764191ef7b3b06d8a2eeb5c7f
 runc:
  Version:          1.1.10
  GitCommit:        v1.1.10-0-g18a0cb0
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

9、将当前用户添加到docker组

避免每次使用Docker时都需要使用sudo(默认情况下,只有root用户和docker组的用户才能运行Docker命令)

sudo usermod -aG docker $USER

10、重启docker服务

service docker restart

你可能感兴趣的:(#,Docker,工具使用,linux,docker,服务器)