docker安装部署

一、docker的安装和部署

1.国内源安装docker-ce(在线安装)

1)配置流量转发(centos7 linux内核)

cat <<EOF > /etc/sysctl.d/docker.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0
net.ipv4.ip_forward=1
EOF

2)加载修改内核的参数,配置文件,按下列命令顺序进行

[root@localhost ~]# modprobe br_netfilter
[root@localhost ~]# sysctl -p /etc/sysctl.d/docker.conf

3)下载docker

[root@docker ~]# yum remove docker                                                 #先删除旧的版本
>                    docker-ce     \
>                     docker-ce-cli  \                   
>                      docker-ce-rootless-extras  \ 
>                      docker-scan-plugin \
>                   docker-client \
>                   docker-client-latest \
>                   docker-common \
>                   docker-latest \
>                   docker-latest-logrotate \
>                   docker-logrotate \
>                   docker-engine
Loaded plugins: fastestmirror, langpacks
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
[root@docker ~]# yum install -y yum-utils                                          #安装yum-utils,主要提供yum-config-manager命令
[root@docker ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo    #下载并安装docker的仓库
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                                    #提示安装成功了
[root@docker ~]# yum list docker-ce --showduplicates | sort -r                    #查看可获取的docker版本
 * updates: mirrors.ustc.edu.cn
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror, langpacks
Installed Packages
 * extras: mirrors.ustc.edu.cn
 * epel: hkg.mirror.rackspace.com
docker-ce.x86_64            3:20.10.9-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.9-3.el7                    @docker-ce-stable
docker-ce.x86_64            3:20.10.8-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.7-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.6-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.5-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.4-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.3-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.2-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.1-3.el7                    docker-ce-stable 
[root@docker ~]# yum install docker-ce docker-ce-cli containerd.io                    #直接安装最新的docker版本
[root@docker ~]# yum install docker-ce-20.10.9 docker-ce-cli-20.10.9 containerd.io    #安装指定版本

4)启动docker

[root@docker ~]# systemctl start docker                                            #启动docker
[root@docker ~]# systemctl status docker | grep running                            #查看运行状态
   Active: active (running) since Wed 2022-01-26 00:28:53 CST; 1min 25s ago
[root@docker ~]# 
[root@docker ~]# systemctl enable docker                                            #设置开机自启
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@docker ~]# 

5)设置镜像加速器

docker默认会从外国网站获取镜像,这样在网络不好的情况下镜像拉去得特别慢,所以设置docker从内网的镜像源拉取镜像。

[root@docker ~]# cat /etc/docker/daemon.json                                         #设置镜像加速器
{
    "registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"]
}
[root@docker ~]# systemctl restart docker                                            #重启docker
[root@docker ~]# docker info |tail -5                                                #检查加速器配置是否成功
  127.0.0.0/8
 Registry Mirrors:
  https://b9pmyelo.mirror.aliyuncs.com/                                                #加速器配置成功,仓库已经是阿里云
 Live Restore Enabled: false

[root@docker ~]#

6)查看docker版本

docker  -v

7)处理docker info告警信息

[root@docker ~]# docker info | tail 
WARNING: bridge-nf-call-iptables is disabled                                    #有告警信息
WARNING: bridge-nf-call-ip6tables is disabled
    
[root@docker ~]# vim /etc/sysctl.conf                                            #打开sysctl.conf文件,添加下面两句
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
[root@docker ~]# sysctl -p                                                        #使配置生效,这时docker info就没有告警信息了

 

posted on 2023-04-18 22:49  一先生94  阅读(93)  评论(0编辑  收藏  举报

导航