docker

开发---运维---

制造---维护----

环境的部署比较麻烦,docker的环境部署比较容易

开发项目,要部署其环境,

java ---apk---发布,

原谅的环境都是交叉的,集群,端口,docker就是把它们分离开来。

 docker历史,

2010成立,dotcloud做pass的云计算服务,lxc的有关容器技术,

将自己的容器化技术命名为docker

在容器技术出来之前,都是使用虚拟机技术,

虚拟机,通过软件虚拟出的电脑,笨重,

虚拟机也属于虚拟化技术,Docker容器技术,也是虚拟化技术。

vm,linux centos 原生镜像(一个电脑) 隔离,虚拟开启多个虚拟机啊,

docker ,隔离,镜像,(最核心4m +jdk+mysql )十分小巧,运行镜像就可以了。

秒级启动。

docker基于go语言开发的,

官网,http://www.docker.com docker文档是超级详细的。

文档地址,docs

仓库地址://hub.docker.com

虚拟机技术缺点,

资源占用多,冗余步骤多,启动很慢,

容器化技术,

不是模拟的一个完整的操作系统

DevOps开发运维

应用更快捷的交付,和部署,

传统:一堆帮助文档,安装程序,

docker,打包镜像发布测试,一键运行,

更便捷的升级和扩缩容,

使用了,docker部署应用就和积木一样,

项目打包,为一个镜像,扩展服务器A 服务器B

更简单的系统运维

在容器化之后,我们的开发,测试环境都是高度一致的,

更高速的计算机资源利用:

Docker 是内核级别的虚拟化,可以在一个物理机上运行更多的容器实例,服务器的性能可以被压榨到极致,

docker的安装

镜像(image)
docker镜像是一个模板,可以通过这个模板来创建容器服务,tomcat 镜像,==>run==>tomcat01容器,通过这个镜像可以创建多个容器,(最终服务运行或者项目就是在这个容器中)
容器(container)
docker 利用容器技术,独立运行一个或者一个组应用,通过镜像来创建的,
启动,停止 ,删除,基本命令,
目前就可以把这个容器理解为一个简易的linux
仓库(repository)
仓库就是存放镜像的地方,
仓库分为,共有仓库和私有仓库,
Docker Hub模式是国外的
阿里云都有容器服务器,配置镜像加速。

安装docker

环境准备,

linux基础

centos7

使用远程连接工具连接

#系统内核是3.10以上的
[root@localhost /]# iname -r
-bash: iname: command not found

#系统版本
[root@localhost /]# uname -r
3.10.0-1160.el7.x86_64
[root@localhost /]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

安装

sudo yum remove docker
docker-client
docker-client-latest
docker-common
docker-latest
docker-latest-logrotate
docker-logrotate
docker-engine

#需要的安装包
yum install -y yum-utils

#3.设置镜像的仓库,
[root@localhost /]#sudo yum-config-manager
--add-repo
https://download.docker.com/linux/centos/docker-ce.repo #默认是国外的
#阿里云的镜像服务器推荐使用这个,
[root@localhost /]#yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

#更新索引包
[root@localhost /]#yum makecache fast

#安装docker相关的 docker-ce 社区
[root@localhost /]#sudo yum install docker-ce docker-ce-cli containerd.io
#启动docker
[root@localhost /]#systemctl start docker

#使用docker viersion 查看是否安装成功,
root@localhost /]# docker version
Client: Docker Engine - Community
Version: 20.10.12
API version: 1.41
Go version: go1.16.12
Git commit: e91ed57
Built: Mon Dec 13 11:45:41 2021
OS/Arch: linux/amd64
Context: default
Experimental: true

Server: Docker Engine - Community
Engine:
Version: 20.10.12
API version: 1.41 (minimum version 1.12)
Go version: go1.16.12
Git commit: 459d0df
Built: Mon Dec 13 11:44:05 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.12
GitCommit: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc:
Version: 1.0.2
GitCommit: v1.0.2-0-g52b36a2
docker-init:
Version: 0.19.0
GitCommit: de40ad0

[root@localhost /]# docker run hello-world
Unable to find image 'hello-world:latest' locally #没有寻找到镜像
latest: Pulling from library/hello-world #远程拉取这个镜像
2db29710123e: Pull complete
Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
Status: Downloaded newer image for hello-world:latest #签名信息

Hello from Docker! #信息显示安装成功
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:

  1. The Docker client contacted the Docker daemon.

  2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)

  3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.

  4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/

#查看 hello-world 安装镜像
[root@localhost /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 3 months ago 13.3kB

#卸载依赖
yum remove docker-ce docker-ce-cli containerd.io

#删除资源
rm -rf /var/lib/docker
配置阿里云镜像服务器
加速器地址
https://zk58d2fs.mirror.aliyuncs.com复制

操作文档

Ubuntu

CentOS

Mac

Windows

推荐安装1.10.0以上版本的Docker客户端,参考文档docker-ce
2. 配置镜像加速器

针对Docker客户端版本大于 1.10.0 的用户

您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器

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

回顾helo word镜像
[root@localhost /]# docker run hello-world
Unable to find image 'hello-world:latest' locally #没有寻找到镜像
latest: Pulling from library/hello-world #远程拉取这个镜像
2db29710123e: Pull complete
Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
Status: Downloaded newer image for hello-world:latest #签名信息

Hello from Docker! #信息显示安装成功
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:

  1. The Docker client contacted the Docker daemon.

  2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)

  3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.

  4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/

开始时-->docker会在本机寻址镜像,---->判断本机是否有这个镜像,------>有遍直接运行
没有去docker Hub上下载,----->下载到本地,或者找不到,返回错误,找不到镜像。

底层原理,
docker是一个Client-Sever结构的系统,Docker的守护进程运行在主机上,通过,Socket从客户端访问,DockerServer接受到Docker-Client的指令,就会执行这个命令

docker为什么比vm快,
docker有着比虚拟机更少的抽象层。
docker是利用宿主机的内核,vm是需要Guest OS
所以新建一个容易的时候,docker不需要像虚拟机重新加载系统内核,避免引导,分钟级别,。docker是利用宿主机的操作系统 省略的这个复杂的过程秒级。