自动化项目部署系列:②部署Docker

朱治龙
2022-01-21 / 0 评论 / 70 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2022年02月07日,已超过1066天没有更新,若内容或图片失效,请留言反馈。

容器化部署技术在自动化部署过程中有着举足轻重的位置,本章将讲解docker的安装部署。
安装过程主要参考 docker官网的文档:https://docs.docker.com/engine/install/centos/

安装相关依赖

sudo yum install -y yum-utils

显示信息如下:

[zhuzl@VM-16-6-centos /]$ sudo yum install -y yum-utils
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
epel                                                                                                                       | 4.7 kB  00:00:00
extras                                                                                                                     | 2.9 kB  00:00:00
os                                                                                                                         | 3.6 kB  00:00:00
updates                                                                                                                    | 2.9 kB  00:00:00
(1/3): epel/7/x86_64/updateinfo                                                                                            | 1.0 MB  00:00:00
(2/3): updates/7/x86_64/primary_db                                                                                         |  13 MB  00:00:00
(3/3): epel/7/x86_64/primary_db                                                                                            | 7.0 MB  00:00:01
Package yum-utils-1.1.31-54.el7_8.noarch already installed and latest version
Nothing to do

设置yum 仓库

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

显示显示如下:

[zhuzl@VM-16-6-centos /]$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

安装 Docker

[zhuzl@VM-16-6-centos /]$ sudo yum install docker-ce docker-ce-cli containerd.io
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
docker-ce-stable                                                                                                           | 3.5 kB  00:00:00
(1/2): docker-ce-stable/7/x86_64/primary_db                                                                                |  70 kB  00:00:00
(2/2): docker-ce-stable/7/x86_64/updateinfo                                                                                |   55 B  00:00:01
Resolving Dependencies
--> Running transaction check
---> Package containerd.io.x86_64 0:1.4.12-3.1.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.io-1.4.12-3.1.el7.x86_64
---> Package docker-ce.x86_64 3:20.10.12-3.el7 will be installed
--> Processing Dependency: docker-ce-rootless-extras for package: 3:docker-ce-20.10.12-3.el7.x86_64
--> Processing Dependency: libcgroup for package: 3:docker-ce-20.10.12-3.el7.x86_64
---> Package docker-ce-cli.x86_64 1:20.10.12-3.el7 will be installed
--> Processing Dependency: docker-scan-plugin(x86-64) for package: 1:docker-ce-cli-20.10.12-3.el7.x86_64
--> Running transaction check
---> Package container-selinux.noarch 2:2.119.2-1.911c772.el7_8 will be installed
--> Processing Dependency: policycoreutils-python for package: 2:container-selinux-2.119.2-1.911c772.el7_8.noarch
---> Package docker-ce-rootless-extras.x86_64 0:20.10.12-3.el7 will be installed
--> Processing Dependency: fuse-overlayfs >= 0.7 for package: docker-ce-rootless-extras-20.10.12-3.el7.x86_64
--> Processing Dependency: slirp4netns >= 0.4 for package: docker-ce-rootless-extras-20.10.12-3.el7.x86_64
---> Package docker-scan-plugin.x86_64 0:0.12.0-3.el7 will be installed
---> Package libcgroup.x86_64 0:0.41-21.el7 will be installed
--> Running transaction check
---> Package fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 will be installed
--> Processing Dependency: libfuse3.so.3(FUSE_3.2)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
--> Processing Dependency: libfuse3.so.3(FUSE_3.0)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
--> Processing Dependency: libfuse3.so.3()(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
---> Package policycoreutils-python.x86_64 0:2.5-34.el7 will be installed
--> Processing Dependency: setools-libs >= 3.3.8-4 for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libsemanage-python >= 2.5-14 for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: audit-libs-python >= 2.1.3-4 for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: python-IPy for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.4)(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.2)(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libapol.so.4(VERS_4.0)(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: checkpolicy for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libqpol.so.1()(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libapol.so.4()(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
---> Package slirp4netns.x86_64 0:0.4.3-4.el7_8 will be installed
--> Running transaction check
---> Package audit-libs-python.x86_64 0:2.8.5-4.el7 will be installed
---> Package checkpolicy.x86_64 0:2.5-8.el7 will be installed
---> Package fuse3-libs.x86_64 0:3.6.1-4.el7 will be installed
---> Package libsemanage-python.x86_64 0:2.5-14.el7 will be installed
---> Package python-IPy.noarch 0:0.75-6.el7 will be installed
---> Package setools-libs.x86_64 0:3.3.8-4.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================================
 Package                                  Arch                  Version                                     Repository                       Size
==================================================================================================================================================
Installing:
 containerd.io                            x86_64                1.4.12-3.1.el7                              docker-ce-stable                 28 M
 docker-ce                                x86_64                3:20.10.12-3.el7                            docker-ce-stable                 23 M
 docker-ce-cli                            x86_64                1:20.10.12-3.el7                            docker-ce-stable                 30 M
Installing for dependencies:
 audit-libs-python                        x86_64                2.8.5-4.el7                                 os                               76 k
 checkpolicy                              x86_64                2.5-8.el7                                   os                              295 k
 container-selinux                        noarch                2:2.119.2-1.911c772.el7_8                   extras                           40 k
 docker-ce-rootless-extras                x86_64                20.10.12-3.el7                              docker-ce-stable                8.0 M
 docker-scan-plugin                       x86_64                0.12.0-3.el7                                docker-ce-stable                3.7 M
 fuse-overlayfs                           x86_64                0.7.2-6.el7_8                               extras                           54 k
 fuse3-libs                               x86_64                3.6.1-4.el7                                 extras                           82 k
 libcgroup                                x86_64                0.41-21.el7                                 os                               66 k
 libsemanage-python                       x86_64                2.5-14.el7                                  os                              113 k
 policycoreutils-python                   x86_64                2.5-34.el7                                  os                              457 k
 python-IPy                               noarch                0.75-6.el7                                  os                               32 k
 setools-libs                             x86_64                3.3.8-4.el7                                 os                              620 k
 slirp4netns                              x86_64                0.4.3-4.el7_8                               extras                           81 k

Transaction Summary
==================================================================================================================================================
Install  3 Packages (+13 Dependent packages)

Total download size: 95 M
Installed size: 387 M
Is this ok [y/d/N]: y
Downloading packages:
(1/16): container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm                                                               |  40 kB  00:00:00
(2/16): audit-libs-python-2.8.5-4.el7.x86_64.rpm                                                                           |  76 kB  00:00:00
(3/16): checkpolicy-2.5-8.el7.x86_64.rpm                                                                                   | 295 kB  00:00:00
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-20.10.12-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Public key for docker-ce-20.10.12-3.el7.x86_64.rpm is not installed
(4/16): docker-ce-20.10.12-3.el7.x86_64.rpm                                                                                |  23 MB  00:03:30
(5/16): containerd.io-1.4.12-3.1.el7.x86_64.rpm                                                                            |  28 MB  00:11:41
(6/16): docker-ce-rootless-extras-20.10.12-3.el7.x86_64.rpm                                                                | 8.0 MB  00:02:47
(7/16): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm                                                                            |  54 kB  00:00:00
(8/16): fuse3-libs-3.6.1-4.el7.x86_64.rpm                                                                                  |  82 kB  00:00:00
(9/16): libcgroup-0.41-21.el7.x86_64.rpm                                                                                   |  66 kB  00:00:00
(10/16): libsemanage-python-2.5-14.el7.x86_64.rpm                                                                          | 113 kB  00:00:00
(11/16): python-IPy-0.75-6.el7.noarch.rpm                                                                                  |  32 kB  00:00:00
(12/16): policycoreutils-python-2.5-34.el7.x86_64.rpm                                                                      | 457 kB  00:00:00
(13/16): slirp4netns-0.4.3-4.el7_8.x86_64.rpm                                                                              |  81 kB  00:00:00
(14/16): setools-libs-3.3.8-4.el7.x86_64.rpm                                                                               | 620 kB  00:00:00
(15/16): docker-scan-plugin-0.12.0-3.el7.x86_64.rpm                                                                        | 3.7 MB  00:00:48
(16/16): docker-ce-cli-20.10.12-3.el7.x86_64.rpm                                                                           |  30 MB  00:15:19
--------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                              86 kB/s |  95 MB  00:18:49
Retrieving key from https://download.docker.com/linux/centos/gpg
Importing GPG key 0x621E9F35:
 Userid     : "Docker Release (CE rpm) <docker@docker.com>"
 Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 From       : https://download.docker.com/linux/centos/gpg
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : docker-scan-plugin-0.12.0-3.el7.x86_64                                                                                        1/16
  Installing : 1:docker-ce-cli-20.10.12-3.el7.x86_64                                                                                         2/16
  Installing : libcgroup-0.41-21.el7.x86_64                                                                                                  3/16
  Installing : setools-libs-3.3.8-4.el7.x86_64                                                                                               4/16
  Installing : audit-libs-python-2.8.5-4.el7.x86_64                                                                                          5/16
  Installing : python-IPy-0.75-6.el7.noarch                                                                                                  6/16
  Installing : slirp4netns-0.4.3-4.el7_8.x86_64                                                                                              7/16
  Installing : libsemanage-python-2.5-14.el7.x86_64                                                                                          8/16
  Installing : fuse3-libs-3.6.1-4.el7.x86_64                                                                                                 9/16
  Installing : fuse-overlayfs-0.7.2-6.el7_8.x86_64                                                                                          10/16
  Installing : checkpolicy-2.5-8.el7.x86_64                                                                                                 11/16
  Installing : policycoreutils-python-2.5-34.el7.x86_64                                                                                     12/16
  Installing : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch                                                                           13/16
setsebool:  SELinux is disabled.
  Installing : containerd.io-1.4.12-3.1.el7.x86_64                                                                                          14/16
  Installing : docker-ce-rootless-extras-20.10.12-3.el7.x86_64                                                                              15/16
  Installing : 3:docker-ce-20.10.12-3.el7.x86_64                                                                                            16/16
  Verifying  : checkpolicy-2.5-8.el7.x86_64                                                                                                  1/16
  Verifying  : fuse3-libs-3.6.1-4.el7.x86_64                                                                                                 2/16
  Verifying  : 1:docker-ce-cli-20.10.12-3.el7.x86_64                                                                                         3/16
  Verifying  : fuse-overlayfs-0.7.2-6.el7_8.x86_64                                                                                           4/16
  Verifying  : libsemanage-python-2.5-14.el7.x86_64                                                                                          5/16
  Verifying  : docker-scan-plugin-0.12.0-3.el7.x86_64                                                                                        6/16
  Verifying  : slirp4netns-0.4.3-4.el7_8.x86_64                                                                                              7/16
  Verifying  : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch                                                                            8/16
  Verifying  : python-IPy-0.75-6.el7.noarch                                                                                                  9/16
  Verifying  : policycoreutils-python-2.5-34.el7.x86_64                                                                                     10/16
  Verifying  : audit-libs-python-2.8.5-4.el7.x86_64                                                                                         11/16
  Verifying  : docker-ce-rootless-extras-20.10.12-3.el7.x86_64                                                                              12/16
  Verifying  : containerd.io-1.4.12-3.1.el7.x86_64                                                                                          13/16
  Verifying  : setools-libs-3.3.8-4.el7.x86_64                                                                                              14/16
  Verifying  : 3:docker-ce-20.10.12-3.el7.x86_64                                                                                            15/16
  Verifying  : libcgroup-0.41-21.el7.x86_64                                                                                                 16/16

Installed:
  containerd.io.x86_64 0:1.4.12-3.1.el7            docker-ce.x86_64 3:20.10.12-3.el7            docker-ce-cli.x86_64 1:20.10.12-3.el7

Dependency Installed:
  audit-libs-python.x86_64 0:2.8.5-4.el7             checkpolicy.x86_64 0:2.5-8.el7            container-selinux.noarch 2:2.119.2-1.911c772.el7_8
  docker-ce-rootless-extras.x86_64 0:20.10.12-3.el7  docker-scan-plugin.x86_64 0:0.12.0-3.el7  fuse-overlayfs.x86_64 0:0.7.2-6.el7_8
  fuse3-libs.x86_64 0:3.6.1-4.el7                    libcgroup.x86_64 0:0.41-21.el7            libsemanage-python.x86_64 0:2.5-14.el7
  policycoreutils-python.x86_64 0:2.5-34.el7         python-IPy.noarch 0:0.75-6.el7            setools-libs.x86_64 0:3.3.8-4.el7
  slirp4netns.x86_64 0:0.4.3-4.el7_8

Complete!

启动 Docker 并配置自启动

启动Docker

sudo systemctl start docker

设置开机自启动

# 检查docker版本
[zhuzl@VM-16-6-centos wldata]$ docker -v
Docker version 20.10.12, build e91ed57
# 查看docker已有镜像
[zhuzl@VM-16-6-centos wldata]$ sudo docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
# 设置docker开机启动
[zhuzl@VM-16-6-centos wldata]$ sudo systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[zhuzl@VM-16-6-centos wldata]$

一些配置

使用阿里云配置镜像加速

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://9643wkwg.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

安装portainer

链接地址:https://docs.portainer.io/v/ce-2.11/start/install/server/docker/linux

安装命令

# 创建portainer挂载镜像
sudo docker volume create portainer_data
# 查看磁盘卷信息
sudo docker inspect portainer_data
# docker方式运行portainer
sudo docker run -d -p 8000:8000 -p 9000:9000 -p 9443:9443 --name portainer     --restart=always     -v /var/run/docker.sock:/var/run/docker.sock     -v portainer_data:/data     portainer/portainer-ce:2.11.0

可以使用nginx代理9000端口端外提供服务

0

评论 (0)

取消