docker镜像概念

docker和虚拟机的本质区别

虚拟机运行多个隔离应用
docker运行多个隔离应用

Docker守护进程可以直接与主操作系统进行通信,为各个Docker容器分配资源;它还可以将容器与主操作系统隔离,并将各个容器互相隔离。虚拟机启动需要数分钟,而Docker容器可以在数毫秒内启动。由于没有臃肿的从操作系统,Docker可以节省大量的磁盘空间以及其他系统资源。

基本概念

  • 镜像
  • 容器
  • 仓库

docker镜像

Docker 运行容器前需要本地存在对应的镜像,如果本地不存在该镜像,Docker 会从镜像仓库下载该镜像

  • 获取镜像docker pull,其命令格式为:
$ docker pull [选项] [Docker Registry 地址[:端口号]/]仓库名[:标签]
  • 镜像仓库地址:格式一般是<域名/IP>[:端口号],默认是Docker Hub。
  • 仓库名:两段式<用户名>/<软件名>。对于Docker Hub,如果不给出用户名,则默认为library,即官方镜像。

比如:

$ docker pull python:2.7

2.7: Pulling from library/python
f49cf87b52c1: Pull complete 
7b491c575b06: Pull complete 
b313b08bab3b: Pull complete 
51d6678c3f0e: Pull complete 
09f35bd58db2: Pull complete 
f7e0c30e74c6: Pull complete 
c308c099d654: Pull complete 
339478b61728: Pull complete 
Digest: sha256:2b01bea4f33624010b2ec935a91108e2000fd93b442130aca4c3407e67f803e8
Status: Downloaded newer image for python:2.7
  • 运行docker run
    以镜像为基础启动并运行一个容器。
$ docker run -it --rm python:2.7

Python 2.7.14 (default, Dec 12 2017, 16:55:09) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print 'hello docker python'
hello docker python
>>> 
  • 列出镜像docker images
$ docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
python              2.7                 9e92c8430ba0        2 weeks ago         681 MB
hello-world         latest              f2a91732366c        5 weeks ago         1.85 kB
  • 删除本地镜像:可用 ID、镜像名、摘要删除镜像
$ docker image rm [选项] <镜像1> [<镜像2> ...]
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容