1、安裝環境
1)依賴的基礎環境
64位CPU
linux kernel(內核)3.10+
linux kernel cgroups and namespace
2)查看自己服務器的環境
使用的服務器的版本
[root@hackerlin ~]# cat /etc/redhat-release CentOS Linux release 7.7.1908 (Core)
內核版本
[root@hackerlin ~]# uname -r 3.10.0-1062.el7.x86_64
IP地址
[root@hackerlin ~]# hostname -I 192.168.72.200
2、安裝docker
實際上就是下載一個安裝腳本,再執行安裝(但是此方法不推薦,因為不能選擇版本安裝)
[root@hackerlin ~]# curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
1)centos7(使用yum進行安裝,推薦)
添加docker-ce源信息
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
修改源信息里的地址,讓下載速度更快
sed -i 's@download.docker.com@mirrors.tuna.tsinghua.edu.cn/docker-ce@g' /etc/yum.repos.d/docker-ce.repo
更新並安裝呢dicker-ce
yum makecache fast
yum -y install docker-ce #安裝的是默認最新版本
安裝指定版本的docker
查看都有哪些版本
yum list docker-ce.x86_64 --showduplicates | sort -r
下載指定版本,我這里下載穩定版
yum -y install docker-ce-17.03.2.ce
安裝可能會報錯(如果沒有遇到請忽略)
Error: Package: docker-ce-18.03.1.ce-1.el7.centos.x86_64 (docker-ce-stable)
Requires: container-selinux >= 2.9
報錯原因: 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 成功
yum -y install docker-ce-17.03.2.ce
2) CentOS 7 (二進制安裝,推薦)
到 https://download.docker.com/linux/static/stable/x86_64/ 頁面下載自己需要版本的發布包:
這次安裝文檔版本 docker-18.03.1-ce
下載安裝
mkdir /data wget -P /data/ https://download.docker.com/linux/static/stable/x86_64/docker-18.03.1-ce.tgz cd /data/ tar -xvf docker-18.03.1-ce.tgz
配置啟動腳本
vim /etc/systemd/system/docker.service
[Unit] Description=Docker Application Container Engine Documentation=http://docs.docker.io [Service] Environment="PATH=/data/docker/:/bin:/sbin:/usr/bin:/usr/sbin" EnvironmentFile=-/run/flannel/docker ExecStart=/data/docker/dockerd --log-level=error $DOCKER_NETWORK_OPTIONS ExecReload=/bin/kill -s HUP $MAINPID Restart=on-failure RestartSec=5 LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity Delegate=yes KillMode=process [Install] WantedBy=multi-user.target
配置生效環境變量,方便使用docker命令
vim /etc/profile.d/docker.sh
export PATH=/data/docker:$PATH source /etc/profile.d/docker.sh
配置docker命令補齊腳本
wget -O /usr/share/bash-completion/completions/docker https://raw.githubusercontent.com/alonghub/Docker/master/Resource/docker
配置dockerfile 語法高亮腳本
wget -O /usr/share/vim/vimfiles/doc/dockerfile.txt https://raw.githubusercontent.com/alonghub/Docker/master/Resource/dockerfile.txt wget -O /usr/share/vim/vimfiles/ftdetect/dockerfile.vim https://raw.githubusercontent.com/alonghub/Docker/master/Resource/dockerfile2.vim wget -O /usr/share/vim/vimfiles/syntax/dockerfile.vim https://raw.githubusercontent.com/alonghub/Docker/master/Resource/dockerfile3.vim
3) Ubuntu 14.04 16.04 (使用apt-get進行安裝)
安裝最新版本
# step 1: 安裝必要的一些系統工具
sudo apt-get update
sudo 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 update
sudo apt-get -y install docker-ce
安裝指定版本的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]
3、 配置docker鏡像加速
多種加速方式:
- docker cn
- 阿里雲加速器
- 中國科技大學
- ... ...
(1)docker cn 加速
mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://registry.docker-cn.com"] } EOF
(2)阿里雲加速器
注冊阿里雲賬號,專用加速器地址獲得路徑:
https://cr.console.aliyun.com/#/accelerator
添加加速器到配置文件
sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://xxxxxxx.mirror.aliyuncs.com"] } EOF
阿里雲頁面有操作步驟
4、 配置清空防火牆規則
systemctl stop firewalld && systemctl disable firewalld /usr/sbin/iptables -F && /usr/sbin/iptables -X && /usr/sbin/iptables -F -t nat && /usr/sbin/iptables -X -t nat /usr/sbin/iptables -P FORWARD ACCEPT
5、 啟動docker服務
1)重載docker啟動配置
systemctl daemon-reload
2)將docker設為開機自啟
systemctl start docker.service
3)啟動docker服務
systemctl enable docker.service
4)查看docker版本
docker version Client: Version: 17.03.2-ce API version: 1.27 Go version: go1.7.5 Git commit: f5ec1e2 Built: Tue Jun 27 02:21:36 2017 OS/Arch: linux/amd64 Server: Version: 17.03.2-ce API version: 1.27 (minimum version 1.12) Go version: go1.7.5 Git commit: f5ec1e2 Built: Tue Jun 27 02:21:36 2017 OS/Arch: linux/amd64 Experimental: false