0
点赞
收藏
分享

微信扫一扫

Docker应用之部署安装

生命中最美的是成长 2022-04-13 阅读 108
linux

一、环境准备

1.1 关闭防火墙,并且修改selinux机制。


[root@localhost ~]# systemctl stop firewalld                                              \\停止firewalld服务
[root@localhost ~]# systemctl disable firewalld                                           \\开机不自启
[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
[root@localhost ~]# cat /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

[root@localhost ~]# reboot 															\\重启一下

1.2 配置yum源并且更新rpm包

[root@localhost ~]# mkdir -p /etc/yum.repos.d/bak
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mv *.* bak/
[root@localhost yum.repos.d]# ls
bak
[root@localhost yum.repos.d]# wget https://mirrors.aliyun.com/repo/Centos-7.repo
--2022-04-11 13:29:23--  https://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 39.96.118.189, 39.96.118.196, 39.96.118.195, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|39.96.118.189|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: ‘Centos-7.repo’

******省略******

[root@localhost yum.repos.d]# yum -y clean all && yum makecache         \\清楚缓存
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up everything
******省略******
[root@localhost yum.repos.d]#yum update								\\更新所有的包

1.3 卸载docker以及依赖包。

[root@localhost ~]# yum -y remove docker  docker-client  docker-cli
[root@localhost ~]# yum -y remove ent-latest \ 
> docker-common \ 
> docker-latest \ 
> docker-latest-logrotate \ 
> docker-logrotate \ 
> docker-selinux \ 
> docker-engine-selinux \ 
> docker-engine

1.4 安装gcc和gcc-c++。

[root@localhost ~]# yum -y install gcc gcc-c++

二、安装

2.1 安装依赖包。

[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2

2.2 设置镜像仓库

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

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

[root@localhost ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
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

2.3 更新yum索引。

[root@localhost ~]# yum makecache fast
Loaded plugins: fastestmirror
base                                                     | 3.6 kB     00:00
docker-ce-stable                                         | 3.5 kB     00:00
extras                                                   | 2.9 kB     00:00
updates                                                  | 2.9 kB     00:00
(1/2): docker-ce-stable/7/x86_64/primary_db                |  75 kB   00:00
(2/2): docker-ce-stable/7/x86_64/updateinfo                |   55 B   00:00
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Metadata Cache Created

2.4 安装docker。

[root@localhost ~]# yum -y install docker-ce

2.5 查看docker版本。

[root@localhost ~]# docker -v
Docker version 20.10.14, build a224086                       \\后面的20.10.14是docker的版本号

[root@localhost ~]# yum -y list docker-ce
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Installed Packages
docker-ce.x86_64                  @docker-ce-stable                                       3:20.10.14-3.el7                                                  

2.6 配置docker镜像加速。

1、登录阿里云找到容器服务

https://cr.console.aliyun.com/?spm=a2c4g.11186623.2.7.5daa7627kOSW0h

2、找到镜像加速地址

image

3、配置使用

sudo mkdir -p /etc/docker
#创建一个目录
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://gbdey2h8.mirror.aliyuncs.com"]
}
EOF
#编写配置文件

2.7 配置docker服务。

[root@localhost ~]# ystemctl daemon-reload
[root@localhost ~]# systemctl enable docker									\\docker的开机自启服务
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost ~]# systemctl restart docker								\\重启服务
[root@localhost ~]# ps -aux |grep docker									\\查看docker的进程
root     18424  0.5  5.1 1079024 50052 ?       Ssl  13:55   0:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root     18571  0.0  0.1 112664   972 pts/0    R+   13:55   0:00 grep --color=auto docker

三、docker的命令使用

直接访问bilibili网站里面有更多的命令讲解内容:https://www.bilibili.com/read/cv11960802

举报

相关推荐

0 条评论