镜像就是模版,容器是这个镜像的实例。
就是一个只读的模版,镜像可以用来创建Docker容器,一个镜像可以创建很多容器。容器与镜像的关系类似于面向对象变成的对象与类。
| Docker | 面向对象 |
|---|---|
| 容器 | 对象 |
| 镜像 | 类 |
Docker利用容器(Container)独立运行的一个或一组应用。容器是用镜像创建的运行实例。它可以被启动,开始,停止,删除。每个容器都是相互隔离的,保证安全的平台。可以把容器看作是一个简易版的Linux环境(包括root用户权限,进程空间,用户空间和网络空间等)和运行在其中的应用程序。容器的定义和镜像一模一样,也是一堆层的统一视角,唯一区别在于容器的最上面那一层是可读可写的。 仓库(Repository)
集中存放镜像文件的场所。仓库和仓库注册服务器(Registry)是有区别的。仓库注册服务器上往往存放着多个仓库,每个仓库中又包含了多个镜像,每个镜像又不同的标签。仓库分为公开仓库和私有仓库两种形式。最大公开仓库(Docker hub)。 总结关系
Docker本身是一个容器运行载体称为管理引擎,我们把应用程序和配置依赖打包好形成一个可交付的运行环境,这个打包好的运行环境就似乎image镜像文件,只有通过这个镜像文件才能生成Docker容器。image文件可以看作是容器的模板,Docker根据image生成容器的实例,同一个image文件,可以生成多个同时运行的容器实例。image文件生成的容器实例,本身也是夜歌文件,称为镜像文件。一个容器运行一种服务,当我们需要的时候,就可以通过docker客户端创建一个对应的运行实例,也就是我们容器。仓库就是放了一堆镜像的地方,我们可以把镜像发布到仓库中,需要的时候从仓储中拉下来就行。 Docker安装 环境准备
会使用Linux常用的基本命令准备一台Linux(CentOS 7)准备一款SSH工具链接远程服务器 环境查看
# 查看系统内核 3.10 以上 [root@izuf6akcgealirj602cmxsz ~]# uname -r 3.10.0-693.2.2.el7.x86_64 # 查看系统版本 CentOS 7 以上 [root@izuf6akcgealirj602cmxsz ~]# 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"安装(参考官网文档)
# 卸载旧版
yum remove docker
docker-client
docker-client-latest
docker-common
docker-latest
docker-latest-logrotate
docker-logrotate
docker-engine
# 安装Docker前,需要安装的软件包
yum install -y yum-utils
# 设置镜像仓库
yum-config-manager
--add-repo
https://download.docker.com/linux/centos/docker-ce.repo # 该镜像为默认的,国外仓库
# 推荐使用阿里云镜像仓库
yum-config-manager
--add-repo
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 更新yum软件包索引
yum makecache fast
# 安装Docker docker-ce 社区办 docker-ee 企业版
yum install docker-ce docker-ce-cli containerd.io
# 启动Docker
systemctl start docker
# 查看Docker版本,查看是否安装成功
docker version
测试Docker
# 测试hello-world
[root@izuf6akcgealirj602cmxsz lib]# 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/
查看镜像
# 查看下载的镜像 [root@izuf6akcgealirj602cmxsz lib]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest feb5d9fea6a5 3 months ago 13.3kB卸载Docker
# 1.卸载依赖 yum remove docker-ce docker-ce-cli containerd.io # 2.删除资源 rm -rf /var/lib/docker # "/var/lib/docker" 为Docker默认工作目录 rm -rf /var/lib/containerd # 删除容器目录阿里云镜像加速 登陆阿里云,找到加速镜像服务 找到镜像加速器 配置镜像加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://xxx.mirror.aliyuncs.com"] # 配置自己的阿里云镜像地址
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker



