Docker容器安装配置

Posted jks212454

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker容器安装配置相关的知识,希望对你有一定的参考价值。

一、检查服务器环境

1.系统内核

[root@tianyi ~]# uname -r
4.18.0-80.el8.x86_64
[root@tianyi ~]# cat /proc/version 
Linux version 4.18.0-80.el8.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 8.2.1 20180905 (Red Hat 8.2.1-3) (GCC)) #1 SMP Tue Jun 4 09:19:46 UTC 2019

2.系统版本

[root@tianyi ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="8 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="8"

二、Docker安装

1.Docker官方网址

Docker官网帮助文档

2.卸载旧的版本docker

[root@tianyi ~]#  sudo yum remove docker \\
>                   docker-client \\
>                   docker-client-latest \\
>                   docker-common \\
>                   docker-latest \\
>                   docker-latest-logrotate \\
>                   docker-logrotate \\
>                   docker-engine
No match for argument: docker
No match for argument: docker-client
No match for argument: docker-client-latest
No match for argument: docker-common
No match for argument: docker-latest
No match for argument: docker-latest-logrotate
No match for argument: docker-logrotate
No match for argument: docker-engine
No packages marked for removal.
Dependencies resolved.
Nothing to do.
Complete!

3.需要的安装包

[[root@tianyi yum.repos.d]# yum install -y yum-utils device-mapper-persistent-data lvm2
Last metadata expiration check: 0:09:55 ago on Sat 19 Jun 2021 04:23:16 PM CST.
Package yum-utils-4.0.18-4.el8.noarch is already installed.
Package device-mapper-persistent-data-0.7.6-1.el8.x86_64 is already installed.
Package lvm2-8:2.03.02-6.el8.x86_64 is already installed.
Dependencies resolved.
===============================================================================================================================================
 Package                                         Architecture             Version                               Repository                Size
===============================================================================================================================================
Upgrading:
 device-mapper                                   x86_64                   8:1.02.175-5.el8                      BaseOS                   375 k
 device-mapper-event                             x86_64                   8:1.02.175-5.el8                      BaseOS                   269 k
 device-mapper-event-libs                        x86_64                   8:1.02.175-5.el8                      BaseOS                   269 k
 device-mapper-libs                              x86_64                   8:1.02.175-5.el8                      BaseOS                   408 k
 device-mapper-persistent-data                   x86_64                   0.8.5-4.el8                           BaseOS                   468 k
 lvm2                                            x86_64                   8:2.03.11-5.el8                       BaseOS                   1.6 M
 lvm2-libs                                       x86_64                   8:2.03.11-5.el8                       BaseOS                   1.1 M

Transaction Summary
===============================================================================================================================================
Upgrade  7 Packages

Total download size: 4.5 M
Downloading Packages:
(1/7): device-mapper-event-libs-1.02.175-5.el8.x86_64.rpm                                                       53 kB/s | 269 kB     00:05    
(2/7): device-mapper-1.02.175-5.el8.x86_64.rpm                                                                  73 kB/s | 375 kB     00:05    
(3/7): device-mapper-event-1.02.175-5.el8.x86_64.rpm                                                            52 kB/s | 269 kB     00:05    
(4/7): device-mapper-libs-1.02.175-5.el8.x86_64.rpm                                                             11 MB/s | 408 kB     00:00    
(5/7): device-mapper-persistent-data-0.8.5-4.el8.x86_64.rpm                                                     10 MB/s | 468 kB     00:00    
(6/7): lvm2-libs-2.03.11-5.el8.x86_64.rpm                                                                       14 MB/s | 1.1 MB     00:00    
(7/7): lvm2-2.03.11-5.el8.x86_64.rpm                                                                            16 MB/s | 1.6 MB     00:00    
-----------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                          871 kB/s | 4.5 MB     00:05   

4.设置镜像的仓库

[root@tianyi yum.repos.d]# cat docker-ce.repo 
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/8/x86_64/stable/
enabled=1
gpgcheck=0



5.查看docker所有版本

[root@tianyi yum.repos.d]# yum list docker-ce --showduplicates | sort -r
Last metadata expiration check: 0:11:33 ago on Sat 19 Jun 2021 04:23:16 PM CST.
docker-ce.x86_64                3:20.10.7-3.el8                 docker-ce-stable
docker-ce.x86_64                3:20.10.6-3.el8                 docker-ce-stable
docker-ce.x86_64                3:20.10.5-3.el8                 docker-ce-stable
docker-ce.x86_64                3:20.10.4-3.el8                 docker-ce-stable
docker-ce.x86_64                3:20.10.3-3.el8                 docker-ce-stable
docker-ce.x86_64                3:20.10.2-3.el8                 docker-ce-stable
docker-ce.x86_64                3:20.10.1-3.el8                 docker-ce-stable
docker-ce.x86_64                3:20.10.0-3.el8                 docker-ce-stable
docker-ce.x86_64                3:19.03.15-3.el8                docker-ce-stable
docker-ce.x86_64                3:19.03.14-3.el8                docker-ce-stable
docker-ce.x86_64                3:19.03.13-3.el8                docker-ce-stable
Available Packages

6.安装docker

[root@tianyi yum.repos.d]# yum install --allowerasing docker-ce
Last metadata expiration check: 0:16:31 ago on Sat 19 Jun 2021 04:23:16 PM CST.
Dependencies resolved.
===============================================================================================================================================
 Package                             Architecture     Version                                                 Repository                  Size
===============================================================================================================================================
Installing:
 docker-ce                           x86_64           3:20.10.7-3.el8                                         docker-ce-stable            27 M
Upgrading:
 fuse-overlayfs                      x86_64           1.4.0-3.module_el8.4.0+830+8027e1c4                     AppStream                   72 k
 slirp4netns                         x86_64           1.1.8-1.module_el8.4.0+641+6116a774                     AppStream                   51 k
Installing dependencies:
 containerd.io                       x86_64           1.4.6-3.1.el8                                           docker-ce-stable            34 M
     replacing  runc.x86_64 1.0.0-55.rc5.dev.git2abd837.module_el8.0.0+58+91b614e7
 docker-ce-cli                       x86_64           1:20.10.7-3.el8                                         docker-ce-stable            33 M
 docker-ce-rootless-extras           x86_64           20.10.7-3.el8                                           docker-ce-stable           9.2 M
 docker-scan-plugin                  x86_64           0.8.0-3.el8                                             docker-ce-stable           4.2 M
 fuse-common                         x86_64           3.2.1-12.el8                                            BaseOS                      21 k
 fuse3                               x86_64           3.2.1-12.el8                                            BaseOS                      50 k
 libcgroup                           x86_64           0.41-19.el8                                             BaseOS                      70 k
 libslirp                            x86_64           4.3.1-1.module_el8.4.0+575+63b40ad7                     AppStream                   69 k
Removing dependent packages:
 buildah                             x86_64           1.5-3.gite94b4f9.module_el8.0.0+58+91b614e7             @AppStream                  20 M

Transaction Summary
===============================================================================================================================================
Install  9 Packages
Upgrade  2 Packages
Remove   1 Package

Total download size: 107 M
Is this ok [y/N]: y

[root@tianyi yum.repos.d]#  yum install docker-ce docker-ce-cli containerd.io
Last metadata expiration check: 0:01:22 ago on Sat 19 Jun 2021 04:14:46 PM CST.

7.启动docker服务

[root@tianyi yum.repos.d]# systemctl start docker
[root@tianyi yum.repos.d]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-06-19 16:43:04 CST; 21s ago
     Docs: https://docs.docker.com
 Main PID: 9017 (dockerd)
    Tasks: 8
   Memory: 48.3M
   CGroup: /system.slice/docker.service
           └─9017 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Jun 19 16:43:02 tianyi dockerd[9017]: time="2021-06-19T16:43:02.076357438+08:00" level=warning msg="Your kernel does not support cgroup blkio >
Jun 19 16:43:02 tianyi dockerd[9017]: time="2021-06-19T16:43:02.076378964+08:00" level=warning msg="Your kernel does not support cgroup blkio >
Jun 19 16:43:02 tianyi dockerd[9017]: time="2021-06-19T16:43:02.076520838+08:00" level=info msg="Loading containers: start."
Jun 19 16:43:03 tianyi dockerd[9017]: time="2021-06-19T16:43:03.722799159+08:00" level=info msg="Default bridge (docker0) is assigned with an >
Jun 19 16:43:04 tianyi dockerd[9017]: time="2021-06-19T16:43:04.259472522+08:00" level=info msg="Firewalld: interface docker0 already part of >
Jun 19 16:43:04 tianyi dockerd[9017]: time="2021-06-19T16:43:04.391777195+08:00" level=info msg="Loading containers: done."
Jun 19 16:43:04 tianyi dockerd[9017]: time="2021-06-19T16:43:04.490571539+08:00" level=info msg="Docker daemon" commit=b0f5bc3 graphdriver(s)=>
Jun 19 16:43:04 tianyi dockerd[9017]: time="2021-06-19T16:43:04.490671132+08:00" level=info msg="Daemon has completed initialization"
Jun 19 16:43:04 tianyi systemd[1]: Started Docker Application Container Engine.
Jun 19 16:43:04 tianyi dockerd[9017]: time="2021-06-19T16:43:04.536063635+08:00" level=info msg="API listen on /var/run/docker.sock"
lines 1-20/20 (END)

三、查看docker安装版本

[root@tianyi yum.repos.d]# docker version 
Client: Docker Engine - Community
 Version:           20.10.7
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        f0df350
 Built:             Wed Jun  2 11:56:24 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.7
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       b0f5bc3
  Built:            Wed Jun  2 11:54:48 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.6
  GitCommit:        d71fcd7d8303cbf684402823e425e9dd2e99285d
 runc:
  Version:          1.0.0-rc95
  GitCommit:        b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[root@tianyi yum.repos.d]# 

四、Docker常用操作

1.运行hello world

[root@tianyi ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest
[root@tianyi ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    d1165f221234   3 months ago   13.3kB

五、卸载docker

1.卸载相关包

 yum remove docker-ce docker-ce-cli containerd.io

2.清空环境

 sudo rm -rf /var/lib/docker
 sudo rm -rf /var/lib/containerd

以上是关于Docker容器安装配置的主要内容,如果未能解决你的问题,请参考以下文章

Docker: 基础介绍及配置安装 [一]

Docker容器安装配置

Docker镜像制作和管理

Linux下的docker容器安装教程

Docker删除报错:Error response from daemon: conflict: unable to delete 08b152afcfae (must be forced)(代码片段

Docker教程-3-Tomcat容器的安装配置使用