Docker image 镜像介绍
来源:互联网 发布:统一数据交换平台 编辑:程序博客网 时间:2024/05/29 14:19
操作镜像
使用 docker 命令行操作 docker 镜像
获取镜像
使用「docker pull +镜像名称」从网络上下载image镜像
core@localhost ~ $ docker pullUsage: docker pull NAME[:TAG]Pull an image or a repository from the registrycore@localhost ~/php $ docker pull ubuntu#pull +镜像的名称会下载该镜像集的laste tag的镜像Pulling repository ubuntu2185fd50e2ca: Pulling dependent layers9cbaf023786c: Pulling dependent layers3db9c44f4520: Pulling dependent layersa9561eb1b190: Pulling dependent layers195eb90b5349: Pulling dependent layers463ff6be4238: Pulling dependent layersc5881f11ded9: Pulling dependent layers511136ea3c5a: Download complete97fd97495e49: Downloading [=====> ] 6.868 MB/67.5 MB 10m20s.....core@localhost ~/php $ docker pull ubuntu:14.04#表示下载该镜像集中14.04 tag的镜像core@localhost ~/php $ docker pull dl.dockerpool.com:5000/alexeiled/docker-oracle-xe-11g#下载其他非官方仓库中的镜像,一般网站会给出详细的 pull 命令Pulling repository dl.dockerpool.com:5000/alexeiled/docker-oracle-xe-11gba16d5d5e1aa: Pulling image (latest) from dl.dockerpool.com:5000/alexeiled/docker-oracle-xe-11g, endpoint: http://dl.dockerpool.com:5000ba16d5d5e1aa: Download complete8dbd9e392a96: Download complete#这一串数字是表示文件系统的层次,docker 的镜像和容器就是这一层一层的文件系统组成的215be6e94fbb: Download completeef2887b77b73: Download complete97774de1565b: Download completec6a02636680f: Download complete2ae911074081: Download completee1787c817b10: Download complete5e312dc5fae8: Download completecb35ce95b58c: Download complete5f0e28679c8e: Download complete...
列出镜像
使用「docker images」列出本地宿主主机上拥有的image镜像
core@localhost ~ $ docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEbase/163 latest 468d347c06bc 28 hours ago 249.1 MBtest/supervisord latest 468d347c06bc 28 hours ago 249.1 MBubuntu 14.04 1357f421be38 4 days ago 192.7 MBdl.dockerpool.com:5000/ubuntu 14.04 1357f421be38 4 days ago 192.7 MBdl.dockerpool.com:5000/mysql 5.7 e95cbb9f48ea 6 days ago 258.6 MBmysql 5.7 e95cbb9f48ea 6 days ago 258.6 MBmysql latest 9a09222edf60 6 days ago 235.6 MBtutum/lamp latest 4b32789c7d66 5 weeks ago 469.8 MBtutum/tomcat 8.0 866eb07a675e 6 weeks ago 539.4 MBtutum/tomcat latest 02e84f04100e 6 weeks ago 539.4 MBdl.dockerpool.com:5000/alexeiled/docker-oracle-xe-11g latest ba16d5d5e1aa 7 months ago 2.388 GB此处共有5列,分别表示镜像的名称、镜像的tag标记、镜像的唯一 image id、创建时间、大小
创建镜像
创建镜像的方法有 2 种:
1. 从文件系统导入
目前可用的文件系统主要是openvz的模板
比如:下载了一个ubuntu14.04的镜像 cat ubuntu-14.04-x86_64-minimal.tar.gz |docker import - ubuntu:14.04 然后用docker images看下:
core@localhost ~ $ docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEubuntu 14.04 05ac7c0b9383 17 seconds ago 215.5 MB
就多了一个我们的ubuntu镜像
2. 从 dockerfile 创建
dockerfile的内容后面章节详细介绍
3. 从现有的容器 commit 提交到一个新的 image
core@localhost ~ $ docker commitUsage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]Create a new image from a container's changes -a, --author="" Author (e.g., "John Hannibal Smith <hannibal@a-team.com>") #填写作者信息 -m, --message="" Commit message #填写提交信息 -p, --pause=true Pause container during commit #如果容器还在运行,先暂停容器core@localhost ~ $ docker run -ti ubuntu:14.04 /bin/bash#创建一个只有bash程序的容器root@a925cb40b3f0:/# touch test#在容器中建立一个文件root@a925cb40b3f0:/# exit#退出exitcore@localhost ~ $ docker commit a92 for_test#将刚才的容器提交为一个叫 for_test 的镜像,这里我们使用容器的 id 来指定我们要提交的容器,也可以使用容器的名字,他们都是唯一的9e9c814023bcffc3e67e892a235afe61b02f66a947d2747f724bd317dda02f27#返回新镜像的 idcore@localhost ~ $ docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEfor_test latest 9e9c814023bc 4 seconds ago 192.7 MB
删除镜像
使用「docker rmi + 镜像 id」删除镜像,当还有容器使用该镜像的时候是无法删除的。
core@localhost ~ $ docker rmiUsage: docker rmi IMAGE [IMAGE...]Remove one or more images -f, --force=false Force removal of the image --no-prune=false Do not delete untagged parentscore@localhost ~ $ docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEfor_test latest 60734a0ee3d6 3 seconds ago 192.7 MBbase/163 latest 468d347c06bc 29 hours ago 249.1 MBtest/supervisord latest 468d347c06bc 29 hours ago 249.1 MBubuntu 14.04 1357f421be38 4 days ago 192.7 MBdl.dockerpool.com:5000/ubuntu 14.04 1357f421be38 4 days ago 192.7 MBdl.dockerpool.com:5000/mysql 5.7 e95cbb9f48ea 6 days ago 258.6 MBmysql 5.7 e95cbb9f48ea 6 days ago 258.6 MBmysql latest 9a09222edf60 6 days ago 235.6 MBtutum/lamp latest 4b32789c7d66 5 weeks ago 469.8 MBtutum/tomcat 8.0 866eb07a675e 6 weeks ago 539.4 MBtutum/tomcat latest 02e84f04100e 6 weeks ago 539.4 MBdl.dockerpool.com:5000/alexeiled/docker-oracle-xe-11g latest ba16d5d5e1aa 7 months ago 2.388 GBcore@localhost ~ $ docker rmi 9a0#当我们删除镜像 9a0 即 mysql:latest 镜像时,它删除了这个镜像所附带的所有aufs层Untagged: mysql:latestDeleted: 9a09222edf600a03ea48bd23cfa363841e45a8715237e3a58cb0167f0e8bad54Deleted: 4daeda4ad839a152a3b649672bd5135977d7f81866d3bc0e16d0af3f65cc8af6Deleted: cf07a411bf0883bd632940e8108dac49c64456a47f7390507de5685bbd6daf85Deleted: 4f513746df18b222a07bb8d76d4b6d29752ce5dcb69bfad0ce92e6c1449a3821Deleted: 228ecd435c8a29d25b77999036701a27f2d67874c915bb8eb9fb175b1f98aa60Deleted: 37e4b3932afa186924a09eab332bc8ebec3aac8bac074314ed9a2d1e94547f50Deleted: 898883ccfcee705e440547e30e240cb025c12410d7c9e4d2bcb11973ba075975Deleted: 0a09ddcf99b7fd8fcb3525c41b54696038ecf13677f4459f1c98c742ffa60ab2Deleted: 35bc8591e39be5089265a093e234d13a4b155a01d2ab9e8904eafa81664fb597Deleted: 857e856e4481d59ee88a4cdedd9aaf855666bd494fa38506e6788361c0af4cdacore@localhost ~ $ docker ps#使用 -ps 参数可以看到目前有上个容器在运行,其中一个容器是以tutum/lamp:laste镜像启动的CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES9cb2e45814e0 tutum/lamp:latest "/run.sh" 4 hours ago Up 4 hours 0.0.0.0:3306->3306/tcp, 0.0.0.0:8080->80/tcp loving_feynmane3c136d76b44 tutum/tomcat:8.0 "/run.sh" 6 hours ago Up 6 hours 0.0.0.0:80->8080/tcp tomcat001fe9e65aaf58c dl.dockerpool.com:5000/mysql:5.7 "/entrypoint.sh mysq 6 hours ago Up 6 hours 3306/tcp db001,tomcat001/tomysqlcore@localhost ~ $ docker rmi 4b3#当我们试图删除tutum/lamp:laste 镜像时,提示我们目前还有容器在使用该镜像,无法删除,如需删除则需要停止容器并用-f 参数删除镜像Error response from daemon: Conflict, cannot delete 4b32789c7d66 because the running container 9cb2e45814e0 is using it (docker untagged the image), stop it and use -f to force2014/10/15 08:23:59 Error: failed to remove one or more images
搜寻镜像
使用「docker search + 关键字」搜索共享的镜像,默认搜索官方仓库的镜像,搜索私有仓库的语法在私有仓库章节详细介绍。
core@localhost ~ $ docker searchUsage: docker search TERMSearch the Docker Hub for images --automated=false Only show automated builds --no-trunc=false Don't truncate output -s, --stars=0 Only displays with at least x stars#一般使用不带参数的搜寻即可,比如要搜寻mysql关键字的 imagecore@localhost ~ $ docker search mysql#返回的信息有5列,分别代表镜像集名称,镜像的描述,被收藏的次数,时候属于官方出品,时候支持自动创建NAME DESCRIPTION STARS OFFICIAL AUTOMATEDmysql MySQL is a widely used, open-source relati... 193 [OK]tutum/mysql MySQL Server image - listens in port 3306.... 69 [OK]orchardup/mysql 36 [OK]tutum/lamp LAMP image - Apache listens in port 80, an... 30 [OK]tutum/wordpress Wordpress Docker image - listens in port 8... 24 [OK]paintedfox/mariadb A docker image for running MariaDB 5.5, a ... 19 [OK]dockerfile/mysql Trusted automated MySQL (http://dev.mysql.... 11 [OK]anapsix/gitlab-ci GitLab-CI Continuous Integration in Docker... 11 [OK]centurylink/drupal Drupal docker image without a DB included ... 10 [OK]google/mysql MySQL server for Google Compute Engine 10 [OK]stenote/docker-lemp MySQL 5.6、PHP 5.5、Nginx、Memcache 9 [OK]
上传镜像
使用「docker push +关键字 」上传镜像到官方仓库,上传私有仓库的语法在私有仓库章节详细介绍。
core@localhost ~ $ docker pushUsage: docker push NAME[:TAG]Push an image or a repository to the registrycore@localhost ~ $ docker push base/163The push refers to a repository [base/163] (len: 1)Sending image listPlease login prior to push:Username: waitfishPassword:Email: xxx@xxx.com第一次上传需要填写在dockerhub注册的帐号信息
更多内容请关注 http://www.dockerpool.com
2 0
- Docker image 镜像介绍
- docker: 构建openldap镜像(image)
- Docker镜像服务image.Store
- docker镜像仓库介绍
- docker强制批量删除none的image镜像
- Docker基础镜像-从iso到image
- Docker中如何删除image(镜像)
- docker强制删除none的image镜像
- docker批量删除none的image镜像
- Docker容器技术介绍(二) --- Docker镜像操作
- [Docker]Docker镜像
- 不通过docker registry共享下载的image(docker镜像本地迁移)
- 【Docker】docker镜像原理
- 【Docker】Docker构建镜像
- 使用docker容器定制镜像(image)并部署简单 web应用
- Docker三个基本概念镜像(Image)容器(Container)仓库(Repository)
- Docker镜像
- 关于docker镜像
- 十个鲜为人知的 Linux 命令 - Part 3
- NYOJ109 数列转换 【守恒法】
- Python学习笔记——生成器,yeild语句
- HTTP Keep-Alive详解
- Git系列之使用GitHub
- Docker image 镜像介绍
- Java中数据库连接池原理机制的详细讲解 http://blog.csdn.net/ilibaba/article/details/3996962
- Lua
- 国外程序员整理的机器学习资源大全
- 10 个鲜为人知的 Linux 命令 - Part 1
- JVM简介 java学习步骤
- 全志A20方案双USB的host配置
- Highstock生成股票K线图
- 10 个鲜为人知的 Linux 命令 - Part 2