Docker安装的yum安装方式和二进制安装方式,并且配置docker镜像加速

1.基于centos 7,修改yum源安装

[root@bbs ~]# wget -O /etc/yum.repos.d/docker.repo  https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo --no-check-certificate
[root@bbs ~]# yum list docker-ce.x86_64  --showduplicates | sort -r
[root@bbs ~]# vim /etc/yum.repos.d/docker.repo 
          :% s#download.docker.com#mirrors.tuna.tsinghua.edu.cn/docker-ce#g
          #然后wq保存退出
#上面一行是进入编辑模式后,
#把里面安装包的来源由docker官网的源替换成清华大学镜像站的源,这样安装东西起来很快速简单
[root@bbs ~]# yum clean all
[root@bbs ~]# yum install docker-ce
#这里安装的直接就是最新版,如果想安装某个版本,可以根据yum list docker-ce.x86_64  --showduplicates | sort -r,筛选出合适自己的版本选择安装
[root@bbs ~]# docker -v
Docker version 20.10.17, build 100c701
[root@bbs ~]# systemctl enable docker --now
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

2.二进制安装
首先,先下载软件包,然后进行解压到指定目录,创建软链接

[root@localhost ~]# wget -c https://download.docker.com/linux/static/stable/x86_64/docker-20.10.17.tgz
[root@localhost ~]# ll
-rw-r--r--. 1 root root 64988857 Jun  6 17:56 docker-20.10.17.tgz
[root@localhost ~]# tar xf docker-20.10.17.tgz -C /usr/local
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ll
total 0
drwxr-xr-x. 2 root   root     6 Apr 10  2018 bin
drwxrwxr-x. 2 redhat redhat 169 Jun  6 16:03 docker
drwxr-xr-x. 2 root   root     6 Apr 10  2018 etc
drwxr-xr-x. 2 root   root     6 Apr 10  2018 games
drwxr-xr-x. 2 root   root     6 Apr 10  2018 include
drwxr-xr-x. 2 root   root     6 Apr 10  2018 lib
drwxr-xr-x. 2 root   root     6 Apr 10  2018 lib64
drwxr-xr-x. 2 root   root     6 Apr 10  2018 libexec
drwxr-xr-x. 2 root   root     6 Apr 10  2018 sbin
drwxr-xr-x. 5 root   root    49 Mar 26 06:01 share
drwxr-xr-x. 2 root   root     6 Apr 10  2018 src
[root@localhost local]# cd docker/
[root@localhost docker]# ll
total 204048
-rwxr-xr-x. 1 redhat redhat 39838504 Jun  6 16:03 containerd
-rwxr-xr-x. 1 redhat redhat  7585792 Jun  6 16:03 containerd-shim
-rwxr-xr-x. 1 redhat redhat  9859072 Jun  6 16:03 containerd-shim-runc-v2
-rwxr-xr-x. 1 redhat redhat 23834624 Jun  6 16:03 ctr
-rwxr-xr-x. 1 redhat redhat 50511896 Jun  6 16:03 docker
-rwxr-xr-x. 1 redhat redhat 60261480 Jun  6 16:03 dockerd
-rwxr-xr-x. 1 redhat redhat   704520 Jun  6 16:03 docker-init
-rwxr-xr-x. 1 redhat redhat  2559454 Jun  6 16:03 docker-proxy
-rwxr-xr-x. 1 redhat redhat 13774272 Jun  6 16:03 runc
[root@localhost docker]# ln -sv /usr/local/docker/* /usr/bin/
#这里创建软链接主要是因为docker、contained、runc
#这里可以知道docker是客户端要使用的命令,所以需要创建软链接,而且容器也是使用docker来启动的
‘/usr/bin/containerd’ -> ‘/usr/local/docker/containerd’
‘/usr/bin/containerd-shim’ -> ‘/usr/local/docker/containerd-shim’
‘/usr/bin/containerd-shim-runc-v2’ -> ‘/usr/local/docker/containerd-shim-runc-v2’
‘/usr/bin/ctr’ -> ‘/usr/local/docker/ctr’
‘/usr/bin/docker’ -> ‘/usr/local/docker/docker’
‘/usr/bin/dockerd’ -> ‘/usr/local/docker/dockerd’
‘/usr/bin/docker-init’ -> ‘/usr/local/docker/docker-init’
‘/usr/bin/docker-proxy’ -> ‘/usr/local/docker/docker-proxy’
‘/usr/bin/runc’ -> ‘/usr/local/docker/runc’

然后,配置docker的服务脚本,这下面是属于官方的配置文件,可用

[root@localhost system]# vim /usr/lib/systemd/system/docker.service 

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket containerd.service

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

# kill only the docker process, not all processes in the cgroup
KillMode=process
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target

[root@localhost system]# vim /usr/lib/systemd/system/docker.socket 

[Unit]
Description=Docker Socket for the API

[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker

[Install]
WantedBy=sockets.target


[root@localhost system]# vim /usr/lib/systemd/system/containerd.service 

# Copyright The containerd Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target

[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/bin/containerd

Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
LimitNOFILE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999

[Install]
WantedBy=multi-user.target
[root@localhost system]# vim /usr/lib/systemd/system/[email protected] 

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Container Getty on /dev/pts/%I
Documentation=man:agetty(8) man:machinectl(1)
After=systemd-user-sessions.service plymouth-quit-wait.service
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Container Getty on /dev/pts/%I
Documentation=man:agetty(8) man:machinectl(1)
After=systemd-user-sessions.service plymouth-quit-wait.service
After=rc-local.service getty-pre.target
Before=getty.target
IgnoreOnIsolate=yes
ConditionPathExists=/dev/pts/%I

[Service]
ExecStart=-/sbin/agetty --noclear --keep-baud pts/%I 115200,38400,9600 $TERM
Type=idle
Restart=always
RestartSec=0
UtmpIdentifier=pts/%I
TTYPath=/dev/pts/%I
TTYReset=yes
TTYVHangup=yes
KillMode=process
IgnoreSIGPIPE=no
SendSIGHUP=yes
[root@localhost system]# groupadd -r docker
[root@localhost system]# systemctl enable --now docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

然后,创建docker组,启动服务,这样docker的二进制安装方式就配置好了。

下面进行配置docker的镜像加速

打开阿里云,控制台搜索镜像,点击容器服务列表的容器镜像服务,打开之后,点击镜像加速器,然后可以照着配置就行

[root@localhost system]# mkdir /etc/docker
[root@localhost system]# tee /etc/docker/daemon.json <<-'EOF'
 {
  "registry-mirrors": ["https://0zkmck3p.mirror.aliyuncs.com"]
}
> EOF
[root@localhost system]# systemctl daemon-reload
[root@localhost system]# systemctl restart docker

你可能感兴趣的:(Docker,docker,linux,运维,后端,架构)