镜像和容器
如果曾经做过 VM 管理员,可以把 Docker 镜像理解为 VM 模板,而运行的VM就是容器 如果你是名研发人员,则可以将镜像理解为类(Class),而容器就是对象 用一句话来说镜像是容器的模板,容器是镜像的运行实例镜像仓库服务
Docker 镜像存储在镜像仓库服务(Image Registry)当中。用户可以从Registry进行镜像下载和访问,可分为公有和私有两类Registry。 公有镜像仓库: Docker Hub是Docker公司为公众提供的托管Registry。 Quay.io现为Red Hat下的公共托管Registry。 私有镜像仓库: 企业可以用Docker Registry构建私有的Registry。 Registry本身是一个开源项目,可以用于搭建私有Registry。 最常用的公用镜像仓库就是Docker Hub,Docker Hub是目前世界上最大的容器镜像仓库,由Docker公司维护,里面有Docker公司提供的镜像及大量用户上传的镜像。以下是它的地址 https://hub.docker.com/ Docker Hub的优点: 为开发者提供了海量Docker镜像,供免费下载学习和使用; 拥有完善的账户管理系统,为用户提供付费扩容; 服务器采用分布式部署,支持负载均衡; 支持镜像上传、下载、查询、删除及属性设置等多种操作; 支持在线编译镜像; 后端采用分布式存储,可容灾备份; 其核心是Docker distribution,在开源社区上设计维护,会不断更新和完善; 提供企业版Docker Hub,为企业级用户提供一站式解决方案。镜像和分层
当进行修改或增加新的内容时,就会在当前镜像层之上,创建新的镜像层。最常用的base镜像是各Linux发行版的Docker镜像,如ubuntu、centos等。 举一个简单的例子,假如基于 Ubuntu Linux 16.04 创建一个新的镜像,这就是新镜像的第一层;如果在该镜像中添加 Python 包,就会在基础镜像层之上创建第二个镜像层;如果继续添加一个安全补丁,就会创建第三个镜像层。 该镜像当前已经包含 3 个镜像层,如下图所示(这只是一个用于演示的很简单的例子)。
常用的镜像操作
拉取镜像
所有的 Docker 镜像都起始于一个基础镜像层,从官方仓库拉取镜像时,docker image pull 命令的格式如下: docker image pull : 示例:让我们拉取一个ubuntu吧[root@localhost ~]# docker image pull ubuntu:latest
latest: Pulling from library/ubuntu
e96e057aae67: Pull complete
Digest: sha256:4b1d0c4a2d2aaf63b37111f34eb9fa89fa1bf53dd6e4ca954d47caebca4005c2
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest
列出镜像
docker images [OPTIONS] [REPOSITORY]
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 eef0fab001e8 12 days ago 495MB
ubuntu latest a8780b506fa4 2 weeks ago 77.8MB
查看镜像的详细信息
docker inspect [OPTION] CONTAINER|IMAGE [CONTAINER|IMAGE...]
[root@localhost ~]# docker inspect ubuntu
[
{
"Id": "sha256:a8780b506fa4eeb1d0779a3c92c8d5d3e6a656c758135f62826768da458b5235",
"RepoTags": [
"ubuntu:latest"
],
"RepoDigests": [
"ubuntu@sha256:4b1d0c4a2d2aaf63b37111f34eb9fa89fa1bf53dd6e4ca954d47caebca4005c2"
],
"Parent": "",
"Comment": "",
..........
查找镜像
你想知道有哪些镜像,docker search命令可以帮助我们搜索Docker Hub[root@localhost ~]# docker search ubuntu
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux operating sys… 15223 [OK]
websphere-liberty WebSphere Liberty multi-architecture images … 290 [OK]
ubuntu-upstart DEPRECATED, as is Upstart (find other proces… 112 [OK]
neurodebian NeuroDebian provides neuroscience research s… 96 [OK]
ubuntu/nginx Nginx, a high-performance reverse proxy & we… 65
open-liberty Open Liberty multi-architecture images based… 56 [OK]
ubuntu-debootstrap DEPRECATED; use "ubuntu" instead 49 [OK]
ubuntu/apache2 Apache, a secure & extensible open-source HT… 47
ubuntu/squid Squid is a caching proxy for the Web. Long-t… 43
ubuntu/mysql MySQL open source fast, stable, multi-thread… 38
ubuntu/prometheus Prometheus is a systems and service monitori… 32
ubuntu/bind9 BIND 9 is a very flexible, full-featured DNS… 32
kasmweb/ubuntu-bionic-desktop Ubuntu productivity desktop for Kasm Workspa… 32
ubuntu/postgres PostgreSQL is an open source object-relation… 22
ubuntu/redis Redis, an open source key-value store. Long-… 15
ubuntu/kafka Apache Kafka, a distributed event streaming … 13
ubuntu/prometheus-alertmanager Alertmanager handles client alerts from Prom… 8
ubuntu/grafana Grafana, a feature rich metrics dashboard & … 6
ubuntu/zookeeper ZooKeeper maintains configuration informatio… 5
ubuntu/memcached Memcached, in-memory keyvalue store for smal… 5
ubuntu/dotnet-runtime Chiselled Ubuntu runtime image for .NET apps… 5
ubuntu/telegraf Telegraf collects, processes, aggregates & w… 4
ubuntu/dotnet-deps Chiselled Ubuntu for self-contained .NET & A… 4
ubuntu/cortex Cortex provides storage for Prometheus. Long… 3
ubuntu/cassandra Cassandra, an open source NoSQL distributed … 2
删除镜像
[root@localhost ~]# docker rmi ubuntu
Untagged: ubuntu:latest
Untagged: ubuntu@sha256:4b1d0c4a2d2aaf63b37111f34eb9fa89fa1bf53dd6e4ca954d47caebca4005c2
Deleted: sha256:a8780b506fa4eeb1d0779a3c92c8d5d3e6a656c758135f62826768da458b5235
Deleted: sha256:f4a670ac65b68f8757aea863ac0de19e627c0ea57165abad8094eae512ca7dad
文章来源:https://www.cnaaa.net,转载请注明出处:https://www.cnaaa.net/archives/6132