docker快速入门

 

学习目标:

了解 docker特点和场景

docker是什么

这一节,我们从定义、场景、历史这三个方面来学习
 
docker是什么?
Docker is the company driving(推动) the container movement and the  only container platform provider to address every application across the  hybrid cloud(混合云). Today’s businesses are under pressure to digitally  transform(数字化转型) but are constrained(限制) by existing applications  and infrastructure while rationalizing an increasingly diverse portfolio  of clouds, datacenters and application architectures. Docker enables  true independence between applications and infrastructure and developers  and IT ops to unlock their potential and creates a model for better  collaboration and innovation.

 

 

Docker是一个开源的容器引擎,它基于LXC容器技术,使用Go语言开发。
源代码托管在Github上,并遵从Apache2.0协议。
Docker采用C/S架构,其可以轻松的为任何应用创建一个轻量级的、可移植的、自给自足的容器。
简单来说:Docker就是一种快速解决生产问题的一种技术手段。
 
Docker生活场景:

 

 

 

 

 

 

 

图一:动画片《七龙珠》里面的胶囊               图二:1号胶囊启动后的效果
 
官方资料:
Docker 官网:http://www.docker.com
Github Docker 源码:https://github.com/docker/docker
Docker理念
构建:
龙珠里的胶囊,将你需要的场景构建好,装在一个小胶囊里
运输:
随身携带着房子、车子等,非常方便
运行:
只需要你轻轻按一下胶囊,找个合适的地方一放,就ok了
 
优缺点
优点:
多:    适用场景多
快:    环境部署快、更新快
好:    好多人在用,东西好
省:    省钱省力省人工(123原则)
 
缺点:
太腻歪人:  依赖操作系统
不善于沟通:依赖网络
不善理财:  银行U盾等场景不能用
 

部署docker

这一节,我们从软件源配置、基础软件安装、docker安装六个方面来学习
软件源配置
官网参考:
https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/#upgrade-docker-after-using-the-convenience-script
基础软件源

cd /etc/apt/

mv sources.list sources.list.bak

vim sources.list

# sohu shangdong

deb http://mirrors.sohu.com/ubuntu/ trusty main restricted universe multiverse

deb http://mirrors.sohu.com/ubuntu/ trusty-security main restricted universe  multiverse

deb http://mirrors.sohu.com/ubuntu/ trusty-updates main restricted universe multiverse

deb http://mirrors.sohu.com/ubuntu/ trusty-proposed main restricted universe  multiverse

deb http://mirrors.sohu.com/ubuntu/ trusty-backports main restricted universe  multiverse

 

# 163 guangdong

deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse

deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse

deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse

deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse

deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe  multiverse

 

# tsinghua.edu

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe  multiverse

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted  universe multiverse

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted  universe multiverse

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted  universe multiverse

 

# aliyun

deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse  partner

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe  multiverse

deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe  multiverse

deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe  multiverse

 

# neu.edu

deb http://mirror.neu.edu.cn/ubuntu/ xenial main restricted universe multiverse  partner

deb http://mirror.neu.edu.cn/ubuntu/ xenial-updates main restricted universe  multiverse

deb http://mirror.neu.edu.cn/ubuntu/ xenial-backports main restricted universe  multiverse

deb http://mirror.neu.edu.cn/ubuntu/ xenial-security main restricted universe  multiverse

 
安装依赖软件

apt-get update

apt-get install apt-transport-https ca-certificates curl  software-properties-common -y

使用官方推荐源

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add  -

add-apt-repository "deb [arch=amd64]  https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

 
使用阿里云的源{推荐1}

curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo  apt-key add -

add-apt-repository "deb [arch=amd64]  https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

 
使用清华的源{推荐2}

curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg  | sudo apt-key add -

add-apt-repository "deb [arch=amd64]  https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs)  stable"

 
检查

apt-get update

 
docker软件安装
查看支持的docker版本

apt-cache madison docker-ce

安装docker

apt-get install docker-ce -y

注:
可以指定版本安装docker:
apt-get install docker-ce=<VERSION> -y
 
启动docker

systemctl start docker

systemctl status docker

注意:

    ubuntu安装完毕后,默认就开启服务了

测试docker

docker version

 
网卡区别:
安装前:只有ens33和lo网卡
安装后:docker启动后,多出来了docker0网卡,网卡地址172.17.0.1
 
docker服务命令格式:
systemctl [参数] docker
参数详解:
start      开启服务
stop       关闭
restart    重启
status     状态
 
删除docker命令:

yum remove docker-ce

rm -rf /var/lib/docker/

rm -rf /etc/docker

 
基本目录
docker基本目录简介
/etc/docker/             docker的认证目录
/var/lib/docker/         docker的应用目录
 

docker加速器

这一节,我们从加速器简介,加速器配置这两个方面来学习
 
加速器简介
    在国内使用docker的官方镜像源,会因为网络的原因,造成无法下载,或者一直处于超时。所以我们使用 daocloud 的方法进行加速配置。
方法:
访问 daocloud.io 网站,登录 daocloud 账户

 

 
点击右上角的加速器

 

 

在新窗口处会显示一条命令,

 

 

我们执行这条命令

curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s  http://74f21445.m.daocloud.io

加速器配置
修改daemon.json文件,增加绿色背景字体内容

# cat /etc/docker/daemon.json

{"registry-mirrors": ["http://74f21445.m.daocloud.io"],  "insecure-registries": []}

注意:
docker cloud加速器的默认内容是少了一条配置,所以我们要编辑文件在后面加上绿色背景的内容,然后再重启docker
 
重启docker

systemctl restart docker

 
posted @ 2021-12-26 22:37  养柱  阅读(167)  评论(0)    收藏  举报