首页 Docker教程Docker-基础入门以及安装

Docker-容器相关核心技术

Docker-命令帮助以及验证

运维派隶属马哥教育旗下专业运维社区,是国内成立最早的IT运维技术社区,欢迎关注公众号:yunweipai
领取学习更多免费Linux云计算、Python、Docker、K8s教程关注公众号:马哥linux运维

Docker安装及基础命令介绍

Docker 安装准备

官方网址:https://www.docker.com/

OS系统版本选择:

Docker 目前已经支持多种操作系统的安装运行,比如Ubuntu、CentOS、Redhat、Debian、Fedora,甚至是还支持了Mac和Windows,在linux系统上需要内核版本在3.10或以上

Docker版本选择:

docker版本号之前一直是0.X版本或1.X版本,但是从2017年3月1号开始改为每个季度发布一次稳版,其版本号规则也统一变更为YY.MM,例如17.09表示是2017年9月份发布的

Docker之前没有区分版本,但是2017年推出(将docker更名为)新的项目Moby,github地址:https://github.com/moby/moby,Moby项目属于Docker项目的全新上游,Docker将是一个隶属于的Moby的子产品,而且之后的版本之后开始区分为 CE(Docker Community Edition,社区版本)和 EE(Docker Enterprise Edition,企业收费版),CE社区版本和EE企业版本都是每个季度发布一个新版本,但是EE版本提供后期安全维护1年,而CE版本是4个月,以下为官方原文:

https://blog.docker.com/2017/03/docker-enterprise-edition/

Docker CE and EE are released quarterly, and CE also has a monthly “Edge” option. Each Docker EE release is supported and maintained for one year and receives security and critical bugfixes during that period. We are also improving Docker CE maintainability by maintaining each quarterly CE release for 4 months. That gets Docker CE users a new 1-month window to update from one version to the next.

如果要布署到kubernets上,需要查看相关kubernets对docker版本要求的说明,比如:

https://github.com/kubernetes/kubernetes/blob/v1.17.2/CHANGELOG-1.17.md

安装和删除方法
Ubuntu 安装和删除Docker

官方文档:https://docs.docker.com/install/linux/docker-ce/ubuntu/

Ubuntu 14.04/16.04/18.04 安装docker

# step 1: 安装必要的一些系统工具
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
# step 2: 安装GPG证书
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# Step 3: 写入软件源信息
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# Step 4: 更新并安装Docker-CE
sudo apt-get -y update
sudo apt-get -y install docker-ce

# 安装指定版本的Docker-CE:
# Step 1: 查找Docker-CE的版本:
apt-cache madison docker-ce 
 docker-ce | 5:19.03.5~3-0~ubuntu-bionic | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:19.03.4~3-0~ubuntu-bionic | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:19.03.3~3-0~ubuntu-bionic | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:19.03.2~3-0~ubuntu-bionic | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:19.03.1~3-0~ubuntu-bionic | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:19.03.0~3-0~ubuntu-bionic | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:18.09.9~3-0~ubuntu-bionic | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:18.09.8~3-0~ubuntu-bionic | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:18.09.7~3-0~ubuntu-bionic | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:18.09.6~3-0~ubuntu-bionic | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:18.09.5~3-0~ubuntu-bionic | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:18.09.4~3-0~ubuntu-bionic | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:18.09.3~3-0~ubuntu-bionic | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:18.09.2~3-0~ubuntu-bionic | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:18.09.1~3-0~ubuntu-bionic | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:18.09.0~3-0~ubuntu-bionic | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 18.06.3~ce~3-0~ubuntu | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 18.06.2~ce~3-0~ubuntu | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 18.06.1~ce~3-0~ubuntu | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 18.06.0~ce~3-0~ubuntu | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 18.03.1~ce~3-0~ubuntu | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages

# Step 2: 安装指定版本的Docker-CE: (VERSION例如上面的17.03.1~ce-0~ubuntu-xenial)
sudo apt-get -y install docker-ce=[VERSION] docker-ce-cli=[VERSION]

删除docker

[root@ubuntu ~]#apt purge docker-ce
[root@ubuntu ~]#rm -rf /var/lib/docker

实战案例: 基于 ubuntu1804 的 docker-ce 安装脚本

[root@ubuntu1804 ~]#cat install_docker_ubuntu.sh
#!/bin/bash
#Description: Install docker on Ubuntu1804
#Version:1.0
#Date:2020-01-22

COLOR="echo -e \\033[1;31m"
END="\033[m"
DOCKER_VERSION="5:19.03.5~3-0~ubuntu-bionic"

install_docker(){
dpkg -s docker-ce &> /dev/null && {COLOR}"Docker已安装,退出"{END} && exit
apt update
apt  -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu (lsb_release -cs) stable"
apt update{COLOR}"Docker有以下版本"{END}
apt-cache madison docker-ce{COLOR}"5秒后即将安装: docker-"{DOCKER_VERSION}" 版本....."{END}
{COLOR}"如果想安装其它Docker版本,请按ctrl+c键退出,修改版本再执行"{END}
sleep 5

apt -y  install docker-ce={DOCKER_VERSION} docker-ce-cli={DOCKER_VERSION}

mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
      "registry-mirrors": ["https://si7y70hh.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
docker version && {COLOR}"Docker 安装成功"{END} ||  {COLOR}"Docker 安装失败"{END}
}
install_docker

范例:查看docker相关文件

[root@ubuntu1804 ~]#dpkg -L docker-ce
/.
/etc
/etc/default
/etc/default/docker
/etc/init
/etc/init/docker.conf
/etc/init.d
/etc/init.d/docker
/lib
/lib/systemd
/lib/systemd/system
/lib/systemd/system/docker.service
/lib/systemd/system/docker.socket
/usr
/usr/bin
/usr/bin/docker-init
/usr/bin/docker-proxy
/usr/bin/dockerd
/usr/share
/usr/share/doc
/usr/share/doc/docker-ce
/usr/share/doc/docker-ce/README.md
/usr/share/doc/docker-ce/changelog.Debian.gz
/var
/var/lib
/var/lib/docker-engine
/var/lib/docker-engine/distribution_based_engine.json
[root@ubuntu1804 ~]#
CentOS 安装和删除Docker

官方文档:https://docs.docker.com/install/linux/docker-ce/centos/

CentOS 6 因内核太旧,即使支持安装docker,但会有各种问题,不建议安装

CentOS 7 的 extras 源虽然可以安装docker,但包比较旧,建议从官方源或镜像源站点下载安装docker

CentOS 8 有新技术 podman 代替 docker

因此建议在CentOS 7 上安装 docker

#extras 源中包名为docker
[root@centos7 ~]#yum list docker
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
Available Packages
docker.x86_64      2:1.13.1-103.git7f2769b.el7.centos                            extras

下载rpm包安装:

官方rpm包下载地址:

https://download.docker.com/linux/centos/7/x86_64/stable/Packages/

阿里镜像下载地址:

https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/

通过yum源安装:

由于官网的yum源太慢,下面使用阿里云的Yum源进行安装

rm -rf /etc/yum.repos.d/*
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum clean all 
yum -y install docker-ce
systemctl enable --now docker

删除 docker

[root@centos7 ~]#yum remove docker-ce
[root@centos7 ~]#rm -rf /var/lib/docker

范例: CentOS 7 基于阿里云的安装docker方法

# step 1: 安装必要的一些系统工具
yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3: 更新并安装Docker-CE
yum makecache fast
yum -y install docker-ce
# Step 4: 开启Docker服务
service docker start

# 注意:
# 官方软件源默认启用了最新的软件,您可以通过编辑软件源的方式获取各个版本的软件包。例如官方并没有将测试版本的软件源置为可用,您可以通过以下方式开启。同理可以开启各种测试版本等。
# vim /etc/yum.repos.d/docker-ee.repo
#   将[docker-ce-test]下方的enabled=0修改为enabled=1
#
# 安装指定版本的Docker-CE:
# Step 1: 查找Docker-CE的版本:
# yum list docker-ce.x86_64 --showduplicates | sort -r
#   Loading mirror speeds from cached hostfile
#   Loaded plugins: branch, fastestmirror, langpacks
#   docker-ce.x86_64            17.03.1.ce-1.el7.centos            docker-ce-stable
#   docker-ce.x86_64            17.03.1.ce-1.el7.centos            @docker-ce-stable
#   docker-ce.x86_64            17.03.0.ce-1.el7.centos            docker-ce-stable
#   Available Packages
# Step2: 安装指定版本的Docker-CE: (VERSION例如上面的17.03.0.ce.1-1.el7.centos)
yum -y install docker-ce-[VERSION]

范例:在CentOS 7.6上安装docker

[root@centos7 ~]#cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 
[root@centos7 ~]#ls /etc/yum.repos.d/
backup  base.repo
[root@centos7 ~]#wget -P /etc/yum.repos.d/ https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Saving to: ‘/etc/yum.repos.d/docker-ce.repo’
100%[====================================================================>] 2,640       --.-K/s   in 0s      

2020-01-23 21:56:21 (505 MB/s) - ‘/etc/yum.repos.d/docker-ce.repo’ saved [2640/2640]

[root@centos7 ~]#ls /etc/yum.repos.d/
backup  base.repo  docker-ce.repo
[root@centos7 ~]#yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base docker-ce-stable epel extras
Cleaning up list of fastest mirrors
[root@centos7 ~]#yum repolist 
repo id                    repo name                                            status
base                       CentOS                                               10,019
docker-ce-stable/x86_64    Docker CE Stable - x86_64                                63
epel/7/x86_64              EPEL                                                 13,513
extras/7/x86_64            extras                                                  307
repolist: 23,902
[root@centos7 ~]#yum list docker-ce* --showduplicates | sort -r
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
docker-ce.x86_64                3:19.03.5-3.el7                 docker-ce-stable
docker-ce.x86_64                3:19.03.4-3.el7                 docker-ce-stable
docker-ce.x86_64                3:19.03.3-3.el7                 docker-ce-stable
docker-ce.x86_64                3:19.03.2-3.el7                 docker-ce-stable
docker-ce.x86_64                3:19.03.1-3.el7                 docker-ce-stable
docker-ce.x86_64                3:19.03.0-3.el7                 docker-ce-stable
docker-ce.x86_64                3:18.09.9-3.el7                 docker-ce-stable
docker-ce.x86_64                3:18.09.8-3.el7                 docker-ce-stable
docker-ce.x86_64                3:18.09.7-3.el7                 docker-ce-stable
docker-ce.x86_64                3:18.09.6-3.el7                 docker-ce-stable
docker-ce.x86_64                3:18.09.5-3.el7                 docker-ce-stable
docker-ce.x86_64                3:18.09.4-3.el7                 docker-ce-stable
docker-ce.x86_64                3:18.09.3-3.el7                 docker-ce-stable
docker-ce.x86_64                3:18.09.2-3.el7                 docker-ce-stable
docker-ce.x86_64                3:18.09.1-3.el7                 docker-ce-stable
docker-ce.x86_64                3:18.09.0-3.el7                 docker-ce-stable
docker-ce.x86_64                18.06.3.ce-3.el7                docker-ce-stable
docker-ce.x86_64                18.06.2.ce-3.el7                docker-ce-stable
docker-ce.x86_64                18.06.1.ce-3.el7                docker-ce-stable
docker-ce.x86_64                18.06.0.ce-3.el7                docker-ce-stable
docker-ce.x86_64                18.03.1.ce-1.el7.centos         docker-ce-stable
docker-ce.x86_64                18.03.0.ce-1.el7.centos         docker-ce-stable
docker-ce.x86_64                17.12.1.ce-1.el7.centos         docker-ce-stable
docker-ce.x86_64                17.12.0.ce-1.el7.centos         docker-ce-stable
docker-ce.x86_64                17.09.1.ce-1.el7.centos         docker-ce-stable
docker-ce.x86_64                17.09.0.ce-1.el7.centos         docker-ce-stable
docker-ce.x86_64                17.06.2.ce-1.el7.centos         docker-ce-stable
docker-ce.x86_64                17.06.1.ce-1.el7.centos         docker-ce-stable
docker-ce.x86_64                17.06.0.ce-1.el7.centos         docker-ce-stable
docker-ce.x86_64                17.03.3.ce-1.el7                docker-ce-stable
docker-ce.x86_64                17.03.2.ce-1.el7.centos         docker-ce-stable
docker-ce.x86_64                17.03.1.ce-1.el7.centos         docker-ce-stable
docker-ce.x86_64                17.03.0.ce-1.el7.centos         docker-ce-stable
docker-ce-selinux.noarch        17.03.3.ce-1.el7                docker-ce-stable
docker-ce-selinux.noarch        17.03.2.ce-1.el7.centos         docker-ce-stable
docker-ce-selinux.noarch        17.03.1.ce-1.el7.centos         docker-ce-stable
docker-ce-selinux.noarch        17.03.0.ce-1.el7.centos         docker-ce-stable
docker-ce-cli.x86_64            1:19.03.5-3.el7                 docker-ce-stable
docker-ce-cli.x86_64            1:19.03.4-3.el7                 docker-ce-stable
docker-ce-cli.x86_64            1:19.03.3-3.el7                 docker-ce-stable
docker-ce-cli.x86_64            1:19.03.2-3.el7                 docker-ce-stable
docker-ce-cli.x86_64            1:19.03.1-3.el7                 docker-ce-stable
docker-ce-cli.x86_64            1:19.03.0-3.el7                 docker-ce-stable
docker-ce-cli.x86_64            1:18.09.9-3.el7                 docker-ce-stable
docker-ce-cli.x86_64            1:18.09.8-3.el7                 docker-ce-stable
docker-ce-cli.x86_64            1:18.09.7-3.el7                 docker-ce-stable
docker-ce-cli.x86_64            1:18.09.6-3.el7                 docker-ce-stable
docker-ce-cli.x86_64            1:18.09.5-3.el7                 docker-ce-stable
docker-ce-cli.x86_64            1:18.09.4-3.el7                 docker-ce-stable
docker-ce-cli.x86_64            1:18.09.3-3.el7                 docker-ce-stable
docker-ce-cli.x86_64            1:18.09.2-3.el7                 docker-ce-stable
docker-ce-cli.x86_64            1:18.09.1-3.el7                 docker-ce-stable
docker-ce-cli.x86_64            1:18.09.0-3.el7                 docker-ce-stable
Available Packages
[root@centos7 ~]#yum -y install docker-ce-18.09.9-3.el7 docker-ce-cli-18.09.9-3.el7
Dependencies Resolved

=========================================================================================
 Package                          Arch             Version                   Repository                  Size
=========================================================================================
Installing:
 docker-ce                        x86_64           3:18.09.9-3.el7           docker-ce-stable            21 M
 docker-ce-cli                    x86_64           1:18.09.9-3.el7           docker-ce-stable            16 M
Installing for dependencies:
 audit-libs-python                x86_64           2.8.4-4.el7               base                        76 k
 checkpolicy                      x86_64           2.5-8.el7                 base                       295 k
 container-selinux                noarch           2:2.107-3.el7             extras                      39 k
 containerd.io                    x86_64           1.2.10-3.2.el7            docker-ce-stable            23 M
 libcgroup                        x86_64           0.41-20.el7               base                        66 k
 libsemanage-python               x86_64           2.5-14.el7                base                       113 k
 policycoreutils-python           x86_64           2.5-29.el7                base                       456 k
 python-IPy                       noarch           0.75-6.el7                base                        32 k
 setools-libs                     x86_64           3.3.8-4.el7               base                       620 k

Transaction Summary
==============================================================================================================
Install  2 Packages (+9 Dependent packages)

Total download size: 62 M
Installed size: 258 M
Downloading packages:
(1/4): container-selinux-2.107-3.el7.noarch.rpm                                        |  39 kB  00:00:00     
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/containerd.io-1.2.10-3.2.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Public key for containerd.io-1.2.10-3.2.el7.x86_64.rpm is not installed
(2/4): containerd.io-1.2.10-3.2.el7.x86_64.rpm                                         |  23 MB  00:00:03     
(3/4): docker-ce-18.09.9-3.el7.x86_64.rpm                                              |  21 MB  00:00:04     
(4/4): docker-ce-cli-18.09.9-3.el7.x86_64.rpm                                          |  16 MB  00:00:01                

Complete!
[root@centos7 ~]#docker version
Client:
 Version:           18.09.9
 API version:       1.39
 Go version:        go1.11.13
 Git commit:        039a7df9ba
 Built:             Wed Sep  4 16:51:21 2019
 OS/Arch:           linux/amd64
 Experimental:      false
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[root@centos7 ~]#systemctl restart docker
[root@centos7 ~]#docker version
Client:
 Version:           18.09.9
 API version:       1.39
 Go version:        go1.11.13
 Git commit:        039a7df9ba
 Built:             Wed Sep  4 16:51:21 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.9
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.11.13
  Git commit:       039a7df
  Built:            Wed Sep  4 16:22:32 2019
  OS/Arch:          linux/amd64
  Experimental:     false
[root@centos7 ~]#

范例:基于CentOS 7的一键安装脚本

[root@centos7 ~]#cat install_docker_for_centos7.sh 
#!/bin/bash
#
#********************************************************************
#Author:        wangxiaochun
#QQ:            29308620
#Date:          2020-01-26
#FileName:      install_docker_for_centos7.sh
#URL:           http://www.magedu.com
#Description:       The test script
#Copyright (C):     2020 All rights reserved
#********************************************************************
COLOR="echo -e \\033[1;31m"
END="\033[m"
VERSION="19.03.5-3.el7"
wget -P /etc/yum.repos.d/ https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo  || { {COLOR}"互联网连接失败,请检查网络配置!"{END};exit; }
yum clean all 
yum -y install docker-ce-VERSION docker-ce-cli-VERSION || { {COLOR}"Base,Extras的yum源失败,请检查yum源配置"{END};exit; }

#使用阿里做镜像加速
mkdir -p /etc/docker
cat > /etc/docker/daemon.json <<EOF
{
 "registry-mirrors": ["https://si7y70hh.mirror.aliyuncs.com"]
 }
EOF

systemctl restart docker
docker version && {COLOR}"Docker安装成功"{END} || {COLOR}"Docker安装失败"{END}
Linux 二进制安装

本方法适用于无法上网的主机安装docker

安装文档:https://docs.docker.com/install/linux/docker-ce/binaries/

二进制安装下载路径

https://download.docker.com/linux/

https://mirrors.aliyun.com/docker-ce/linux/static/stable/x86_64/

范例:

[root@centos8 ~]#wget https://download.docker.com/linux/static/stable/x86_64/docker-19.03.5.tgz
--2020-01-24 18:02:55--  https://download.docker.com/linux/static/stable/x86_64/docker-19.03.5.tgz
Resolving download.docker.com (download.docker.com)... 143.204.83.37, 143.204.83.32, 143.204.83.95, ...
Connecting to download.docker.com (download.docker.com)|143.204.83.37|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 63252595 (60M) [application/x-tar]
Saving to: ‘docker-19.03.5.tgz’

docker-19.03.5.tgz          100%[=========================================>]  60.32M  11.3MB/s    in 5.6s    

2020-01-24 18:03:02 (10.7 MB/s) - ‘docker-19.03.5.tgz’ saved [63252595/63252595]

[root@centos8 ~]#tar xvf docker-19.03.5.tgz 
docker/
docker/docker-init
docker/docker
docker/dockerd
docker/runc
docker/ctr
docker/docker-proxy
docker/containerd
docker/containerd-shim
[root@centos8 ~]#cp docker/* /usr/bin/
[root@centos8 ~]#groupadd -r docker

#将Ubuntu1804或CentOS7基于包方式安装的相关文件复制到相应目录下
[root@ubuntu1804 ~]#scp /lib/systemd/system/docker.* /lib/systemd/system/containerd.service  10.0.0.8:/lib/systemd/system/
The authenticity of host '10.0.0.8 (10.0.0.8)' can't be established.
ECDSA key fingerprint is SHA256:8mUO3Wy13Ktt5pRBKaOU40avmw1x0gH5XTPK48CEWoM.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.8' (ECDSA) to the list of known hosts.
root@10.0.0.8's password: 
docker.service                                             100% 1683   650.8KB/s   00:00  docker.socket                                              100%  197   303.3KB/s   00:00 
containerd.service                                         100%  487   516.6KB/s   00:00 

[root@centos8 ~]#systemctl daemon-reload
[root@centos8 ~]#systemctl enable --now docker
[root@centos8 ~]#docker version
Client: Docker Engine - Community
 Version:           19.03.5
 API version:       1.40
 Go version:        go1.12.12
 Git commit:        633a0ea838
 Built:             Wed Nov 13 07:22:05 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.5
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.12
  Git commit:       633a0ea838
  Built:            Wed Nov 13 07:28:45 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.10
  GitCommit:        b34a5c8af56e510852c35414db4c1f4fa6172339
 runc:
  Version:          1.0.0-rc8+dev
  GitCommit:        3e425f80a8c931f88e6d94a8c831b9d5aa481657
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
[root@centos8 ~]#docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:9572f7cdcee8591948c2963463447a53466950b3fc15a247fcad1917ca215a2f
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
[root@centos8 ~]#pstree -p
systemd(1)─┬─NetworkManager(660)─┬─{NetworkManager}(669)
           │                     └─{NetworkManager}(671)
           ├─VGAuthService(662)
           ├─agetty(718)
           ├─atd(712)
           ├─auditd(625)───{auditd}(627)
           ├─automount(905)─┬─{automount}(912)
           │                ├─{automount}(913)
           │                ├─{automount}(930)
           │                └─{automount}(937)
           ├─containerd(679)─┬─{containerd}(693)
           │                 ├─{containerd}(694)
           │                 ├─{containerd}(696)
           │                 ├─{containerd}(704)
           │                 ├─{containerd}(705)
           │                 ├─{containerd}(707)
           │                 └─{containerd}(708)
           ├─crond(713)
           ├─dbus-daemon(658)
           ├─dockerd(908)─┬─{dockerd}(922)
           │              ├─{dockerd}(923)
           │              ├─{dockerd}(925)
           │              ├─{dockerd}(944)
           │              ├─{dockerd}(1028)
           │              ├─{dockerd}(1100)
           │              └─{dockerd}(1114)
           ├─polkitd(659)─┬─{polkitd}(670)
           │              ├─{polkitd}(672)
           │              ├─{polkitd}(677)
           │              ├─{polkitd}(678)
           │              └─{polkitd}(701)
           ├─rngd(664)───{rngd}(666)
           ├─rsyslogd(906)─┬─{rsyslogd}(911)
           │               └─{rsyslogd}(914)
           ├─sshd(675)───sshd(1370)───sshd(1382)───bash(1383)───pstree(1441)
           ├─sssd(661)─┬─sssd_be(688)
           │           └─sssd_nss(703)
           ├─systemd(1373)───(sd-pam)(1376)
           ├─systemd-journal(551)
           ├─systemd-logind(709)
           ├─systemd-udevd(580)
           ├─tuned(674)─┬─{tuned}(915)
           │            ├─{tuned}(934)
           │            └─{tuned}(948)
           └─vmtoolsd(663)
[root@centos8 ~]#
安装podman

范例:在CentOS8上安装docker

#在CentOS8上安装docker会自动安装podman,docker工具只是一个脚本,调用了Podman
[root@centos8 ~]#dnf install docker
[root@centos8 ~]#rpm -ql podman-docker
/usr/bin/docker
[root@centos8 ~]#cat /usr/bin/docker
#!/bin/sh
[ -f /etc/containers/nodocker ] || \
echo "Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg." >&2
exec /usr/bin/podman "$@"
[root@centos8 ~]#podman version
Version:            1.4.2-stable2
RemoteAPI Version:  1
Go Version:         go1.12.8
OS/Arch:            linux/amd64

#修改拉取镜像的地址的顺序,提高速度
[root@centos8 ~]#vim /etc/containers/registries.conf
[registries.search]
registries = ['docker.io','quay.io','registry.redhat.io', 'registry.access.redhat.com']   

本文链接:http://www.yunweipai.com/34762.html

Docker-容器相关核心技术

Docker-命令帮助以及验证

网友评论comments

发表评论

邮箱地址不会被公开。

暂无评论

Copyright © 2012-2021 YUNWEIPAI.COM - 运维派 京ICP备16064699号-6
扫二维码
扫二维码
返回顶部