Docker 安装

Docker 安装

官方网址:https://www.docker.com/

系统版本选择

​ Docker 目前已经支持多种操作系统的安装运行,比如 Ubuntu、CentOS、 Redhat、Debian、Fedora,甚至是还支持了 Mac 和 Windows,在 linux 系统上需要内核版本在 3.10 或以上,docker 版本号之前一直是 0.X 版本或 1.X 版本,但是从 2017 年 3 月 1 号开始改为每个季度发布一次稳版,其版本号规则也统一变更为 YY.MM,例如 17.09 表示是 2017 年 9 月份发布的,本次演示的操作系统使用 Centos 7.5 为例。

Docker版本选择

Docker 之前没有区分版本,但是 2017 年推出(将 docker 更名为)新的项目

Moby,github 地址:https://github.com/moby/mobyMoby 项目属于 Docker 项

目的全新上游,Docker 将是一个隶属于的 Moby 的子产品,而且之后的版本之后开始区分为 CE 版本(社区版本)和 EE(企业收费版),CE 社区版本和 EE 企业版本都是每个季度发布一个新版本,但是 EE 版本提供后期安全维护 1 年,而CE 版本是 4 个月,本次演示的 Docker 版本为 18.09.9 。 ubuntu 1804

1. 通过二进制包安装

设置路径 ,配置service 即可

下载地址: https://download.docker.com/linux/static/stable/x86_64/

wget  https://download.docker.com/linux/static/stable/x86_64/docker-18.09.9.tgz
tar xvf docker-18.09.9.tgz 
cp docker/* /usr/bin/

编辑 vim /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
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
StartLimitBurst=3
StartLimitInterval=60s
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
Delegate=yes
KillMode=process
[Install]
WantedBy=multi-user.target                          

启动docker

systemctl daemon-reload
systemctl  start docker

若遇到报错

Failed to start docker.service: Unit docker.service is masked.

则 执行 下条命令即可

systemctl unmask docker.service

验证 看docke cli 和server 的版本信息

root@z1:~# docker version
Client: Docker Engine - Community
 Version:           18.09.9
 API version:       1.39
 Go version:        go1.11.13
 Git commit:        039a7df9ba
 Built:             Wed Sep  4 16:50:02 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.9
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.11.13
  Git commit:       039a7df9ba
  Built:            Wed Sep  4 16:55:50 2019
  OS/Arch:          linux/amd64
  Experimental:     false

2. apt 安装
# 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 https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# Step 3: 写入软件源信息
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# Step 4: 更新并安装Docker-CE
sudo apt-get -y update

执行 apt-cache madison docker-ce docker -cli 选择需要安装的版本

例:

apt install docker-ce=5:18.09.9~3-0~ubuntu-bionic docker-ce-cli=5:18.09.9~3-0~ubuntu-bionic
3. 验证 docker 信息
root@z1:~# docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 18.09.9
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
runc version: 425e105d5a03fabd737a126ad93d62a9eeede87f
init version: fec3683
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.15.0-62-generic
Operating System: Ubuntu 18.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.83GiB
Name: z1
ID: OAYZ:OPXK:OGQ5:5KOA:4RQ3:3SMB:WGXL:ZKPL:K4WD:HNYV:3XBI:6QAU
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine

可以看到 docker 的版本信息,docker 使用的存储引擎 以及非安全的docker 仓库信息。

也可以看到 正在运行的容器的数量 和停止的容器数量 ,可以写脚本抓取这些数据用于监控

root@z1:~# docker info |grep Running|awk '{print $2}'
0
4.docker 加速器

​ 浏览器打开 注册或登录阿里云账号, 点击容器镜像服务 https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors,点击左侧的镜像加速器,将会得到一个专属的加速地址,而且下面有使用配置说明

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://n0kig9se.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

用了加速器之后,docker 拉取镜像会加快

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值