docker 安装

docker 安装

文章目录

  • docker 安装
    • 1. centos 安装 (yum) docker
    • 2. docker 1.13 安装
    • 3. docker 17.09.0-ce 安装
    • 4. oracle 7.4 安装 docker
    • 5. ubuntu 安装(apt-get)docker
      • 5.1 设置存储库
      • 5.2 安装 Docker Engine
      • 5.3 卸载 docker
    • 6. Fedora 安装(dnf)docker
      • 6.1 配置源
      • 6.2 安装
      • 6.3 卸载


1. centos 安装 (yum) docker

yum-utils提供了yum-config-manager 效用,并device-mapper-persistent-data和lvm2由需要 devicemapper存储驱动程序

yum install -y yum-utils  device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

可选:启用边缘和测试存储库。这些存储库包含在docker.repo上面的文件中,但默认情况下处于禁用状态。您可以将它们与稳定的存储库一起启用。

sudo yum-config-manager --enable docker-ce-edge
sudo yum-config-manager --enable docker-ce-test

禁用

$ sudo yum-config-manager --disable docker-ce-edge

按版本号排序结果

yum list docker-ce --showduplicates | sort -r

安装 docker

sudo yum -y install docker-ce docker-ce-cli containerd.io docker-compose-plugin

输出:

 yum -y install docker-ce 
Last metadata expiration check: 0:01:27 ago on Wed 24 May 2023 03:47:20 PM CST.
Dependencies resolved.
===================================================================================================================================================================
 Package                                   Architecture           Version                                                   Repository                        Size
===================================================================================================================================================================
Installing:
 docker-ce                                 x86_64                 3:24.0.1-1.el8                                            docker-ce-stable                  24 M
Installing dependencies:
 container-selinux                         noarch                 2:2.205.0-2.module+el8.8.0+1265+fa25dd7a                  appstream                         63 k
 containerd.io                             x86_64                 1.6.21-3.1.el8                                            docker-ce-stable                  34 M
 docker-ce-cli                             x86_64                 1:24.0.1-1.el8                                            docker-ce-stable                 7.2 M
 docker-ce-rootless-extras                 x86_64                 24.0.1-1.el8                                              docker-ce-stable                 4.9 M
 fuse-overlayfs                            x86_64                 1.11-1.module+el8.8.0+1265+fa25dd7a                       appstream                         73 k
 fuse3                                     x86_64                 3.3.0-16.el8                                              baseos                            53 k
 fuse3-libs                                x86_64                 3.3.0-16.el8                                              baseos                            94 k
 libcgroup                                 x86_64                 0.41-19.el8                                               baseos                            69 k
 libslirp                                  x86_64                 4.4.0-1.module+el8.8.0+1265+fa25dd7a                      appstream                         69 k
 slirp4netns                               x86_64                 1.2.0-2.module+el8.8.0+1265+fa25dd7a                      appstream                         53 k
Installing weak dependencies:
 docker-buildx-plugin                      x86_64                 0.10.4-1.el8                                              docker-ce-stable                  12 M
 docker-compose-plugin                     x86_64                 2.18.1-1.el8                                              docker-ce-stable                  12 M

Transaction Summary
===================================================================================================================================================================
Install  13 Packages

Total download size: 94 M
Installed size: 361 M
Downloading Packages:
(1/13): container-selinux-2.205.0-2.module+el8.8.0+1265+fa25dd7a.noarch.rpm                                                        395 kB/s |  63 kB     00:00    
(2/13): fuse-overlayfs-1.11-1.module+el8.8.0+1265+fa25dd7a.x86_64.rpm                                                              445 kB/s |  73 kB     00:00    
(3/13): libslirp-4.4.0-1.module+el8.8.0+1265+fa25dd7a.x86_64.rpm                                                                   410 kB/s |  69 kB     00:00    
(4/13): slirp4netns-1.2.0-2.module+el8.8.0+1265+fa25dd7a.x86_64.rpm                                                                1.1 MB/s |  53 kB     00:00    
(5/13): fuse3-3.3.0-16.el8.x86_64.rpm                                                                                              1.0 MB/s |  53 kB     00:00    
(6/13): libcgroup-0.41-19.el8.x86_64.rpm                                                                                           1.6 MB/s |  69 kB     00:00    
(7/13): fuse3-libs-3.3.0-16.el8.x86_64.rpm                                                                                         1.1 MB/s |  94 kB     00:00    
(8/13): docker-buildx-plugin-0.10.4-1.el8.x86_64.rpm                                                                               5.1 MB/s |  12 MB     00:02    
(9/13): docker-ce-cli-24.0.1-1.el8.x86_64.rpm                                                                                      6.0 MB/s | 7.2 MB     00:01    
(10/13): docker-ce-rootless-extras-24.0.1-1.el8.x86_64.rpm                                                                          10 MB/s | 4.9 MB     00:00    
(11/13): docker-ce-24.0.1-1.el8.x86_64.rpm                                                                                         5.0 MB/s |  24 MB     00:04    
(12/13): containerd.io-1.6.21-3.1.el8.x86_64.rpm                                                                                   6.6 MB/s |  34 MB     00:05    
(13/13): docker-compose-plugin-2.18.1-1.el8.x86_64.rpm                                                                             9.3 MB/s |  12 MB     00:01    
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                               14 MB/s |  94 MB     00:06     
Docker CE Stable - x86_64                                                                                                          3.5 kB/s | 1.6 kB     00:00    
Importing GPG key 0x621E9F35:
 Userid     : "Docker Release (CE rpm) "
 Fingerprint: 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
 From       : https://download.docker.com/linux/centos/gpg
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                           1/1 
  Installing       : docker-compose-plugin-2.18.1-1.el8.x86_64                                                                                                1/13 
  Running scriptlet: docker-compose-plugin-2.18.1-1.el8.x86_64                                                                                                1/13 
  Installing       : fuse3-libs-3.3.0-16.el8.x86_64                                                                                                           2/13 
  Running scriptlet: fuse3-libs-3.3.0-16.el8.x86_64                                                                                                           2/13 
  Running scriptlet: container-selinux-2:2.205.0-2.module+el8.8.0+1265+fa25dd7a.noarch                                                                        3/13 
  Installing       : container-selinux-2:2.205.0-2.module+el8.8.0+1265+fa25dd7a.noarch                                                                        3/13 
  Running scriptlet: container-selinux-2:2.205.0-2.module+el8.8.0+1265+fa25dd7a.noarch                                                                        3/13 
  Installing       : containerd.io-1.6.21-3.1.el8.x86_64                                                                                                      4/13 
  Running scriptlet: containerd.io-1.6.21-3.1.el8.x86_64                                                                                                      4/13 
  Installing       : fuse3-3.3.0-16.el8.x86_64                                                                                                                5/13 
  Installing       : fuse-overlayfs-1.11-1.module+el8.8.0+1265+fa25dd7a.x86_64                                                                                6/13 
  Running scriptlet: fuse-overlayfs-1.11-1.module+el8.8.0+1265+fa25dd7a.x86_64                                                                                6/13 
  Installing       : docker-buildx-plugin-0.10.4-1.el8.x86_64                                                                                                 7/13 
  Running scriptlet: docker-buildx-plugin-0.10.4-1.el8.x86_64                                                                                                 7/13 
  Installing       : docker-ce-cli-1:24.0.1-1.el8.x86_64                                                                                                      8/13 
  Running scriptlet: docker-ce-cli-1:24.0.1-1.el8.x86_64                                                                                                      8/13 
  Running scriptlet: libcgroup-0.41-19.el8.x86_64                                                                                                             9/13 
  Installing       : libcgroup-0.41-19.el8.x86_64                                                                                                             9/13 
  Running scriptlet: libcgroup-0.41-19.el8.x86_64                                                                                                             9/13 
  Installing       : libslirp-4.4.0-1.module+el8.8.0+1265+fa25dd7a.x86_64                                                                                    10/13 
  Installing       : slirp4netns-1.2.0-2.module+el8.8.0+1265+fa25dd7a.x86_64                                                                                 11/13 
  Installing       : docker-ce-rootless-extras-24.0.1-1.el8.x86_64                                                                                           12/13 
  Running scriptlet: docker-ce-rootless-extras-24.0.1-1.el8.x86_64                                                                                           12/13 
  Installing       : docker-ce-3:24.0.1-1.el8.x86_64                                                                                                         13/13 
  Running scriptlet: docker-ce-3:24.0.1-1.el8.x86_64                                                                                                         13/13 
  Running scriptlet: container-selinux-2:2.205.0-2.module+el8.8.0+1265+fa25dd7a.noarch                                                                       13/13 
  Running scriptlet: docker-ce-3:24.0.1-1.el8.x86_64                                                                                                         13/13 
  Verifying        : container-selinux-2:2.205.0-2.module+el8.8.0+1265+fa25dd7a.noarch                                                                        1/13 
  Verifying        : fuse-overlayfs-1.11-1.module+el8.8.0+1265+fa25dd7a.x86_64                                                                                2/13 
  Verifying        : libslirp-4.4.0-1.module+el8.8.0+1265+fa25dd7a.x86_64                                                                                     3/13 
  Verifying        : slirp4netns-1.2.0-2.module+el8.8.0+1265+fa25dd7a.x86_64                                                                                  4/13 
  Verifying        : fuse3-3.3.0-16.el8.x86_64                                                                                                                5/13 
  Verifying        : fuse3-libs-3.3.0-16.el8.x86_64                                                                                                           6/13 
  Verifying        : libcgroup-0.41-19.el8.x86_64                                                                                                             7/13 
  Verifying        : containerd.io-1.6.21-3.1.el8.x86_64                                                                                                      8/13 
  Verifying        : docker-buildx-plugin-0.10.4-1.el8.x86_64                                                                                                 9/13 
  Verifying        : docker-ce-3:24.0.1-1.el8.x86_64                                                                                                         10/13 
  Verifying        : docker-ce-cli-1:24.0.1-1.el8.x86_64                                                                                                     11/13 
  Verifying        : docker-ce-rootless-extras-24.0.1-1.el8.x86_64                                                                                           12/13 
  Verifying        : docker-compose-plugin-2.18.1-1.el8.x86_64                                                                                               13/13 

Installed:
  container-selinux-2:2.205.0-2.module+el8.8.0+1265+fa25dd7a.noarch                    containerd.io-1.6.21-3.1.el8.x86_64                                         
  docker-buildx-plugin-0.10.4-1.el8.x86_64                                             docker-ce-3:24.0.1-1.el8.x86_64                                             
  docker-ce-cli-1:24.0.1-1.el8.x86_64                                                  docker-ce-rootless-extras-24.0.1-1.el8.x86_64                               
  docker-compose-plugin-2.18.1-1.el8.x86_64                                            fuse-overlayfs-1.11-1.module+el8.8.0+1265+fa25dd7a.x86_64                   
  fuse3-3.3.0-16.el8.x86_64                                                            fuse3-libs-3.3.0-16.el8.x86_64                                              
  libcgroup-0.41-19.el8.x86_64                                                         libslirp-4.4.0-1.module+el8.8.0+1265+fa25dd7a.x86_64                        
  slirp4netns-1.2.0-2.module+el8.8.0+1265+fa25dd7a.x86_64                             

Complete!

启动docker并保证docker重启自动拉起

sudo systemctl start docker && systemctl enable docker

运行一个容器

sudo docker run hello-world

卸载Docker包:

sudo yum remove docker-ce

卸载旧版本

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

不会自动删除主机上的图像,容器,卷或自定义配置文件。删除所有图像,容器和卷:

$ sudo rm -rf /var/lib/docker

2. docker 1.13 安装

导入安装源:

rpm --import "https://sks-keyservers.net/pks/lookup?op=get&search=0xee6d536cf7dc86e2d7d56f59a178ac6c6238f52e"

如果没有响应使用:pgp.mit.edu 或keyserver.ubuntu.com

  yum-config-manager --add-repo https://packages.docker.com/1.13/yum/repo/main/centos/7

安装:

  yum makecache fast
  yum install -y docker-engine

注意:安装其他cs版本

  yum list docker-engine.x86_64  --showduplicates |sort -r
  yum install docker-engine-<version>

3. docker 17.09.0-ce 安装

wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
 rpm -ivh epel-release-latest-7.noarch.rpm

wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-17.09.0.ce-1.el7.centos.x86_64.rpm
yum -y install  docker-engine-selinux
yum -y remove  selinux-policy-targeted-3.13.1-192.0.5.el7_5.6.noarch
yum -y install  docker-engine-selinux

yum -y install container-selinux-2.68-1.el7.noarch.rpm
yumdownloader --resolve container-selinux

4. oracle 7.4 安装 docker

wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
 rpm -ivh epel-release-latest-7.noarch.rpm
yum -y install  docker-engine-selinux
yum -y remove  selinux-policy-targeted-3.13.1-192.0.5.el7_5.6.noarch
yum -y install  docker-engine-selinux
yum -y install container-selinux-2.68-1.el7.noarch.rpm
yumdownloader --resolve container-selinux
yum -y install docker-ce

5. ubuntu 安装(apt-get)docker

5.1 设置存储库

  1. 更新apt包索引并安装包,以允许apt通过HTTPS使用存储库
sudo apt-get update
sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
  1. 添加Docker的官方GPG密钥
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
  1. 设置存储库
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

5.2 安装 Docker Engine

sudo apt-get update

默认的umask可能配置错误,导致无法检测到存储库公钥文件。在更新包索引之前,尝试为Docker公钥文件授予读权限:
sudo chmod a+r /etc/apt/keyrings/docker.gpg
sudo apt-get update

默认安装

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

安装指定版本

# 列出可用的版本
$ apt-cache madison docker-ce | awk '{ print $3 }'

5:20.10.16~3-0~ubuntu-jammy
5:20.10.15~3-0~ubuntu-jammy
5:20.10.14~3-0~ubuntu-jammy
5:20.10.13~3-0~ubuntu-jammy

安装指定版本

VERSION_STRING=5:20.10.13~3-0~ubuntu-jammy
sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-compose-plugin

5.3 卸载 docker

sudo apt-get remove docker docker-engine docker.io containerd runc
rm -rf /var/lib/docker

6. Fedora 安装(dnf)docker

6.1 配置源

sudo dnf -y install dnf-plugins-core
sudo dnf config-manager \
    --add-repo \
    https://download.docker.com/linux/fedora/docker-ce.repo

6.2 安装

安装默认版本(最新)

sudo dnf install docker-ce docker-ce-cli containerd.io docker-compose-plugin

安装指定版本

$ dnf list docker-ce  --showduplicates | sort -r

docker-ce.x86_64  3:18.09.1-3.fc28                 docker-ce-stable
docker-ce.x86_64  3:18.09.0-3.fc28                 docker-ce-stable
docker-ce.x86_64  18.06.1.ce-3.fc28                docker-ce-stable
docker-ce.x86_64  18.06.0.ce-3.fc28                docker-ce-stable

$ sudo dnf -y install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io docker-compose-plugin

6.3 卸载

sudo dnf remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine
rm -rf /var/lib/docker/

参考:

  • 安装 docker
  • 下载 docker

你可能感兴趣的:(docker,docker,linux,centos,oracle)