docker的安装部署
centos系统
1、安装环境
[root@inode3 ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core)
[root@inode3 ~]# uname -r 3.10.0-862.el7.x86_64
2、centos7使用yum安装(推荐的方式)
#下载docker-ce的yum源
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
#把docker-ce源的地址修改为清华源的地址
sed -i 's#download.docker.com#mirrors.tuna.tsinghua.edu.cn/docker-ce#g' /etc/yum.repos.d/docker-ce.repo
#更新docker-ce.repo
yum makecache fast
#安装docker-ce
yum install -y docker-ce
下载安装指定版本
#查看docker-ce的版本
[root@inode3 ~]# yum list docker-ce.x86_64 --showduplicates | sort -r
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
Installed Packages
docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stable
docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
Available Packages
......
安装指定版本
yum -y install docker-ce-17.03.2.ce
安装报错(虚拟机中可能会遇到,如果没有报错请忽略)
Error: Package: docker-ce-17.03.2.ce-1.el7.centos.x86_64 (docker-ce-stable) Requires: docker-ce-selinux >= 17.03.2.ce-1.el7.centos
Available: docker-ce-selinux-17.03.0.ce-1.el7.centos.noarch (docker-ce-stable) docker-ce-selinux = 17.03.0.ce-1.el7.centos
Available: docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch (docker-ce-stable) docker-ce-selinux = 17.03.1.ce-1.el7.centos
Available: docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch (docker-ce-stable) docker-ce-selinux = 17.03.2.ce-1.el7.centos
Available: docker-ce-selinux-17.03.3.ce-1.el7.noarch (docker-ce-stable) docker-ce-selinux = 17.03.3.ce-1.el7
报错原因: docker-ce-selinux 版本过低
解决办法:在https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/x86_64/stable/Packages/网站下载对应版本的docker-ce-selinux,安装即可
yum -y install https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-selinux-17.03.3.ce-1.el7.noarch.rpm
重新安装docker-ce-17.03.2.ce成功
这次安装文档版本 docker-18.03.1-ce
(1)下载安装
mkdir /data
cd /data/
wget -c https://download.docker.com/linux/static/stable/x86_64/docker-18.03.1-ce.tgz
tar -xvf docker-18.03.1-ce.tgz
(2)配置启动脚本
vim /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket
[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
[Install]
WantedBy=multi-user.target
(3)配置生效环境变量,方便使用docker命令
cat > /etc/profile.d/docker.sh <<EOF
export PATH=/data/docker:$PATH
EOF
source /etc/profile.d/docker.sh
(4)配置docker命令补齐脚本(可能404)
wget -O /usr/share/bash-completion/completions/docker https://raw.githubusercontent.com/alonghub/Docker/master/Resource/docker
4、Ubuntu 14.04 16.04 (使用apt-get进行安装)
(1)安装最新版本
step 1: 安装必要的一些系统工具
sudo apt-get updatesudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
step 2: 安装GPG证书
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
Step 3: 写入软件源信息
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
Step 4: 更新并安装 Docker-CE
sudo apt-get -y updatesudo apt-get -y install docker-ce
(2)安装指定版本的Docker-CE:
# Step 1: 查找Docker-CE的版本:
# apt-cache madison docker-ce
# docker-ce | 17.03.1~ce-0~ubuntu-xenial | http://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages
# docker-ce | 17.03.0~ce-0~ubuntu-xenial | http://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages
# Step 2: 安装指定版本的Docker-CE: (VERSION 例如上面的 17.03.1~ce-0~ubuntu-xenial)
# sudo apt-get -y install docker-ce=[VERSION]
5、启动docker
[root@inode1 ~]# systemctl start docker
[root@inode1 ~]# ps -ef |grep docker
root 46215 1 2 20:26 ? 00:00:00 /usr/bin/dockerdroot 46218 46215 0 20:26
四、docker命令无法tab键补全
#1、安装bash-complete
yum install -y bash-completion
#2、刷新文件
source /usr/share/bash-completion/completions/docker
source /usr/share/bash-completion/bash_completion
docker连接redis命令
docker exec -it da45019bf760 redis-cli