操作镜像

使用 docker 命令行操作 docker 镜像

获取镜像

使用「docker pull +镜像名称」从网络上下载image镜像

core@localhost ~ $ docker pull

Usage: docker pull NAME[:TAG]

Pull an image or a repository from the registry

core@localhost ~/php $ docker  pull ubuntu
#pull +镜像的名称会下载该镜像集的laste tag的镜像
Pulling repository ubuntu
2185fd50e2ca: Pulling dependent layers
9cbaf023786c: Pulling dependent layers
3db9c44f4520: Pulling dependent layers
a9561eb1b190: Pulling dependent layers
195eb90b5349: Pulling dependent layers
463ff6be4238: Pulling dependent layers
c5881f11ded9: Pulling dependent layers
511136ea3c5a: Download complete
97fd97495e49: 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-11g
ba16d5d5e1aa: Pulling image (latest) from dl.dockerpool.com:5000/alexeiled/docker-oracle-xe-11g, endpoint: http://dl.dockerpool.com:5000ba16d5d5e1aa: Download complete
8dbd9e392a96: Download complete
#这一串数字是表示文件系统的层次,docker 的镜像和容器就是这一层一层的文件系统组成的
215be6e94fbb: Download complete
ef2887b77b73: Download complete
97774de1565b: Download complete
c6a02636680f: Download complete
2ae911074081: Download complete
e1787c817b10: Download complete
5e312dc5fae8: Download complete
cb35ce95b58c: Download complete
5f0e28679c8e: Download complete
...

列出镜像

使用「docker images」列出本地宿主主机上拥有的image镜像

core@localhost ~ $ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
base/163 latest 468d347c06bc 28 hours ago 249.1 MB
test/supervisord latest 468d347c06bc 28 hours ago 249.1 MB
ubuntu 14.04 1357f421be38 4 days ago 192.7 MB
dl.dockerpool.com:5000/ubuntu 14.04 1357f421be38 4 days ago 192.7 MB
dl.dockerpool.com:5000/mysql 5.7 e95cbb9f48ea 6 days ago 258.6 MB
mysql 5.7 e95cbb9f48ea 6 days ago 258.6 MB
mysql latest 9a09222edf60 6 days ago 235.6 MB
tutum/lamp latest 4b32789c7d66 5 weeks ago 469.8 MB
tutum/tomcat 8.0 866eb07a675e 6 weeks ago 539.4 MB
tutum/tomcat latest 02e84f04100e 6 weeks ago 539.4 MB
dl.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 images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu 14.04 05ac7c0b9383 17 seconds ago 215.5 MB

就多了一个我们的ubuntu镜像

2. 从 dockerfile 创建

dockerfile的内容后面章节详细介绍

3. 从现有的容器 commit 提交到一个新的 image

core@localhost ~ $ docker commit

Usage: 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
#退出
exit
core@localhost ~ $ docker commit a92 for_test
#将刚才的容器提交为一个叫 for_test 的镜像,这里我们使用容器的 id 来指定我们要提交的容器,也可以使用容器的名字,他们都是唯一的
9e9c814023bcffc3e67e892a235afe61b02f66a947d2747f724bd317dda02f27
#返回新镜像的 id
core@localhost ~ $ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
for_test latest 9e9c814023bc 4 seconds ago 192.7 MB

删除镜像

使用「docker rmi + 镜像 id」删除镜像,当还有容器使用该镜像的时候是无法删除的。

core@localhost ~ $ docker rmi

Usage: docker rmi IMAGE [IMAGE...]

Remove one or more images

  -f, --force=false    Force removal of the image
--no-prune=false Do not delete untagged parents core@localhost ~ $ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
for_test latest 60734a0ee3d6 3 seconds ago 192.7 MB
base/163 latest 468d347c06bc 29 hours ago 249.1 MB
test/supervisord latest 468d347c06bc 29 hours ago 249.1 MB
ubuntu 14.04 1357f421be38 4 days ago 192.7 MB
dl.dockerpool.com:5000/ubuntu 14.04 1357f421be38 4 days ago 192.7 MB
dl.dockerpool.com:5000/mysql 5.7 e95cbb9f48ea 6 days ago 258.6 MB
mysql 5.7 e95cbb9f48ea 6 days ago 258.6 MB
mysql latest 9a09222edf60 6 days ago 235.6 MB
tutum/lamp latest 4b32789c7d66 5 weeks ago 469.8 MB
tutum/tomcat 8.0 866eb07a675e 6 weeks ago 539.4 MB
tutum/tomcat latest 02e84f04100e 6 weeks ago 539.4 MB
dl.dockerpool.com:5000/alexeiled/docker-oracle-xe-11g latest ba16d5d5e1aa 7 months ago 2.388 GB
core@localhost ~ $ docker rmi 9a0
#当我们删除镜像 9a0 即 mysql:latest 镜像时,它删除了这个镜像所附带的所有aufs层
Untagged: mysql:latest
Deleted: 9a09222edf600a03ea48bd23cfa363841e45a8715237e3a58cb0167f0e8bad54
Deleted: 4daeda4ad839a152a3b649672bd5135977d7f81866d3bc0e16d0af3f65cc8af6
Deleted: cf07a411bf0883bd632940e8108dac49c64456a47f7390507de5685bbd6daf85
Deleted: 4f513746df18b222a07bb8d76d4b6d29752ce5dcb69bfad0ce92e6c1449a3821
Deleted: 228ecd435c8a29d25b77999036701a27f2d67874c915bb8eb9fb175b1f98aa60
Deleted: 37e4b3932afa186924a09eab332bc8ebec3aac8bac074314ed9a2d1e94547f50
Deleted: 898883ccfcee705e440547e30e240cb025c12410d7c9e4d2bcb11973ba075975
Deleted: 0a09ddcf99b7fd8fcb3525c41b54696038ecf13677f4459f1c98c742ffa60ab2
Deleted: 35bc8591e39be5089265a093e234d13a4b155a01d2ab9e8904eafa81664fb597
Deleted: 857e856e4481d59ee88a4cdedd9aaf855666bd494fa38506e6788361c0af4cda
core@localhost ~ $ docker ps
#使用 -ps 参数可以看到目前有上个容器在运行,其中一个容器是以tutum/lamp:laste镜像启动的
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9cb2e45814e0 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_feynman
e3c136d76b44 tutum/tomcat:8.0 "/run.sh" 6 hours ago Up 6 hours 0.0.0.0:80->8080/tcp tomcat001
fe9e65aaf58c dl.dockerpool.com:5000/mysql:5.7 "/entrypoint.sh mysq 6 hours ago Up 6 hours 3306/tcp db001,tomcat001/tomysql
core@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 force
2014/10/15 08:23:59 Error: failed to remove one or more images

搜寻镜像

使用「docker search + 关键字」搜索共享的镜像,默认搜索官方仓库的镜像,搜索私有仓库的语法在私有仓库章节详细介绍。

core@localhost ~ $ docker search

Usage: docker search TERM

Search 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关键字的 image
core@localhost ~ $ docker search mysql
#返回的信息有5列,分别代表镜像集名称,镜像的描述,被收藏的次数,时候属于官方出品,时候支持自动创建
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql 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 push

Usage: docker push NAME[:TAG]

Push an image or a repository to the registry
core@localhost ~ $ docker push base/163
The push refers to a repository [base/163] (len: 1)
Sending image list Please login prior to push:
Username: waitfish
Password:
Email: xxx@xxx.com
第一次上传需要填写在dockerhub注册的帐号信息

docker镜像基本操作的更多相关文章

  1. docker镜像基本操作一

    获取镜像 首先说明一下如何从Docker hub中获取高质量的镜像,从Docker镜像库获取镜像的命令是docker pull .其命令格式为: docker pull [选项] [Docker Re ...

  2. Docker(5):Docker镜像基本操作(上)

    1.获取镜像 可以使用docker pull 命令从网络上下载镜像.该命令的格式为docker pull NAME[:TAG].对于Docker镜像来说,如果不显示地指定TAG,则默认会选择lates ...

  3. Docker镜像和容器

    本节内容: 安装Docker 卸载docker 镜像基本操作 容器基本操作 一.安装Docker Docker 对 Linux 内核版本的最低要求是3.10,如果内核版本低于 3.10 会缺少一些运行 ...

  4. Docker 镜像、容器、仓库的概念及基本操作

    Docker 包括三个基本概念: 镜像(Image)容器(Container)仓库(Repository) 这三部分组成了Docker的整个生命周期,如下图所示,容器是由镜像实例化而来的,这和我们学习 ...

  5. Docker 镜像 && 容器的基本操作

    镜像 && 容器 docker 镜像好比操作系统的镜像(iso) docker 容器好比是已安装运行的操作系统 所以说 docker 镜像文件运行起来之后,就是我们所说的 docker ...

  6. 【实战】Docker入门实践二:Docker服务基本操作 和 测试Hello World

    操作环境 操作系统:CentOS7.2 内存:1GB CPU:2核 Docker服务常用命令 docker服务操作命令如下 service docker start #启动服务 service doc ...

  7. 004.Docker镜像管理

    一 镜像基本操作 镜像是一个包含程序运行必要依赖环境和代码的只读文件,其本质是磁盘上一系列文件的集合.它采用分层的文件系统,将每一次改变以读写层的形式增加到原来的只读文件上.镜像是容器运行的基石. 1 ...

  8. Docker 安装&基本操作

    Docker 安装 Docker 中的三个概念:镜像,容器,仓库 镜像(image):Docker 镜像就是一个只读的模板,镜像可以用来创建 Docker 容器.Docker 提供了一个很简单的机制来 ...

  9. 五十三.Docker概述、部署Docker、Docker镜像、Docker基本命令

    1.安装Docker 准备两台虚拟机,IP为192.168.1.10和192.168.1.20 安装docker-engine 和 docker-engine-selinux 关闭防火墙   **** ...

随机推荐

  1. ABAP-动态程序生成

    科技越来越进步,人也就变的越来越懒,最终的演变就是大脑发达,四肢退化...AI的到来,准备接招吧... 报表若没有过多的用户交互逻辑,一般可通过SQ01配置生成,本文介绍用ABAP方式实现报表程序的动 ...

  2. 系统批量运维管理器pexpect的使用

    # pip install pexpect 或 # easy_install pexpect 1 #!/usr/bin/env python 2 import pexpect 3 child = pe ...

  3. delphi 图片加水印源代码

    unit UWaterMark; interface uses {$IFNDEF DELPHIXE2ANDUP} windows,SysUtils,classes,graphics,Gdiplus; ...

  4. JQUERY伸缩导航

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. 面向对象三大特性一一继承(inheritance)和组合(Composition)

    记住2句话(常识),像个正常人思考! 1.“  is-a ”关系 用 继承! 学生是人,学生继承人这个类, 2. “has-a ”关系 用 组合!电脑有显卡,那么我们就在计算机类中增加显卡属性来复用显 ...

  6. Java web struct入门基础知识

    1.Struts2的前身是Opensymphony的Webwork2,实际上Strut和Webwork2合并后形成Struts2.   2.一个HelloWord示例 1)创建Web应用,所需要的Ja ...

  7. Mysql修改密码办法

    方法1: 用SET PASSWORD命令 首先登录MySQL. 格式:mysql> set password for 用户名@localhost = password('新密码'); 例子:my ...

  8. electron 大体结构

    1.Electron支持的平台: OS XWindowsLinux 2.一个标准的electron app包含的结构: Windows 或是 Linux中:electron/resources/app ...

  9. sql:查询课程号'0312091006'成绩排名第5到第10之间的学生学号

    select top 6 sno from (select top 10 sno,mark from student_Coursewhere ccno='0312091006' order by ma ...

  10. 实例学习SSIS(一)

    网址: http://www.cnblogs.com/tenghoo/archive/2009/10/archive/2009/10/archive/2009/10/archive/2009/10/a ...