Docker Image操作

List Images

列出本地所有Docker image

# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              centos6             25c5298b1a36        2 weeks ago         215.8 MB

可以看到,REPOSITORY是image来源库,此处是centos

TAG:每个image有自己的tag,此处是centos6

使用该image启动Docker container的时候,名字为:centos:centos6

IMAGE ID:每个image有自己独立的ID

下载新的image

查找新的image

众多Docker的使用者会创建自己的image,有部分image就会上传到Docker Hub中,我们可以直接在Docker Hub中查找合适的image。

也可以使用docker search命令查找image

# docker search centos | more
NAME                                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
centos                                            The official build of CentOS.                   685       [OK]
tianon/centos                                     CentOS 5 and 6, created using rinse instea...   29
ansible/centos7-ansible                           Ansible on Centos7                              22                   [OK]
ariya/centos6-teamcity-server                     TeamCity Server 8.1 on CentOS 6                 8                    [OK]
tutum/centos                                      Centos image with SSH access. For the root...   8                    [OK]
berngp/docker-zabbix                              Runs Zabbix Server and Zabbix Web UI on a ...   8                    [OK]
saltstack/centos-6-minimal                                                                        8                    [OK]
blalor/centos                                     Bare-bones base CentOS 6.5 image                7                    [OK]
centos/freeipa                                    FreeIPA in Docker on CentOS                     7
steeef/graphite-centos                            CentOS 6.x with Graphite and Carbon via ng...   6                    [OK]
dockerfiles/centos-lamp                                                                           6                    [OK]
gluster/gluster                                   GlusterFS 3.5 - CentOS 6.5 Docker repo          6                    [OK]
ariya/centos6-teamcity-agent                      Build agent for TeamCity 8.1                    5                    [OK]
tutum/centos-6.4                                  DEPRECATED. Use tutum/centos:6.4 instead. ...   5                    [OK]
jdeathe/centos-ssh-apache-php                     CentOS-6 6.5 x86_64 / Apache / PHP / PHP m...   5                    [OK]
cern/centos-wlcg-wn                               CentosOS 6 image with pre-installed softwa...   4                    

创建新的image

更新现有的image

交互模式启动centos:centos6,安装mysql

# docker run -t -i centos:centos6 /bin/bash
bash-4.1#
bash-4.1# yum install -y mysql mysql-serve

完成后,exit退出交互模式

# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                         PORTS               NAMES
2e9de4d9c350        centos:centos6      /bin/bash           2 minutes ago       Exited (0) 7 seconds ago                           mad_colden   

可以看到刚刚关掉的container ID

# docker commit -m="install mysql" -a="Hongtu Zang" 2e9de4d9c350 centos6:hongtu
5f3bca7952cac8900e08b5fac11cdd1a4941803edbb5442593a171fe574ed961

-m Message,描述信息

-a author,image的创建者

# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED              VIRTUAL SIZE
centos6             hongtu              5f3bca7952ca        About a minute ago   320.3 MB
centos              centos6             25c5298b1a36        2 weeks ago          215.8 MB

可以看到,多出来一个TAG为hongtu的image,是我们刚刚创建好的

从Dockerfile创建image

创建一个Dockerfile

# mkdir hongtu
# cd hongtu/
# touch Dockerfile

编辑Dockerfile内容:

# This is a comment
FROM centos:centos6
MAINTAINER Hongtu Zang <[email protected]>
RUN yum install -y mysql mysql-server

FROM 基础image

MAINTAINER 作者

RUN 需要执行的命令,此处是安装mysql-server

docker run创建新的模板

# docker build -t="hongtu/centos6:v2" .
Sending build context to Docker daemon  2.56 kB
Sending build context to Docker daemon
Step 0 : FROM centos:centos6
 ---> 25c5298b1a36
Step 1 : MAINTAINER Hongtu Zang <[email protected]>
 ---> Using cache
 ---> 52f35fcefd08
Step 2 : RUN yum install -y mysql mysql-server
 ---> Running in 35ab46137fe7
Loaded plugins: fastestmirror
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql.x86_64 0:5.1.73-3.el6_5 will be installed
--> Processing Dependency: mysql-libs = 5.1.73-3.el6_5 for package: mysql-5.1.73-3.el6_5.x86_64
--> Processing Dependency: perl(Sys::Hostname) for package: mysql-5.1.73-3.el6_5.x86_64
--> Processing Dependency: perl(IPC::Open3) for package: mysql-5.1.73-3.el6_5.x86_64
--> Processing Dependency: perl(Getopt::Long) for package: mysql-5.1.73-3.el6_5.x86_64
--> Processing Dependency: perl(File::Temp) for package: mysql-5.1.73-3.el6_5.x86_64
--> Processing Dependency: perl(Fcntl) for package: mysql-5.1.73-3.el6_5.x86_64
--> Processing Dependency: perl(Exporter) for package: mysql-5.1.73-3.el6_5.x86_64
--> Processing Dependency: libmysqlclient_r.so.16(libmysqlclient_16)(64bit) for package: mysql-5.1.73-3.el6_5.x86_64
--> Processing Dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit) for package: mysql-5.1.73-3.el6_5.x86_64
--> Processing Dependency: /usr/bin/perl for package: mysql-5.1.73-3.el6_5.x86_64
--> Processing Dependency: libmysqlclient_r.so.16()(64bit) for package: mysql-5.1.73-3.el6_5.x86_64
--> Processing Dependency: libmysqlclient.so.16()(64bit) for package: mysql-5.1.73-3.el6_5.x86_64
---> Package mysql-server.x86_64 0:5.1.73-3.el6_5 will be installed
--> Processing Dependency: perl-DBI for package: mysql-server-5.1.73-3.el6_5.x86_64
--> Processing Dependency: perl-DBD-MySQL for package: mysql-server-5.1.73-3.el6_5.x86_64
--> Processing Dependency: perl(DBI) for package: mysql-server-5.1.73-3.el6_5.x86_64
--> Running transaction check
---> Package mysql-libs.x86_64 0:5.1.73-3.el6_5 will be installed
---> Package perl.x86_64 4:5.10.1-136.el6_6.1 will be installed
--> Processing Dependency: perl-libs = 4:5.10.1-136.el6_6.1 for package: 4:perl-5.10.1-136.el6_6.1.x86_64
--> Processing Dependency: perl-libs for package: 4:perl-5.10.1-136.el6_6.1.x86_64
--> Processing Dependency: perl(version) for package: 4:perl-5.10.1-136.el6_6.1.x86_64
--> Processing Dependency: perl(Pod::Simple) for package: 4:perl-5.10.1-136.el6_6.1.x86_64
--> Processing Dependency: perl(Module::Pluggable) for package: 4:perl-5.10.1-136.el6_6.1.x86_64
--> Processing Dependency: libperl.so()(64bit) for package: 4:perl-5.10.1-136.el6_6.1.x86_64
---> Package perl-DBD-MySQL.x86_64 0:4.013-3.el6 will be installed
---> Package perl-DBI.x86_64 0:1.609-4.el6 will be installed
--> Running transaction check
---> Package perl-Module-Pluggable.x86_64 1:3.90-136.el6_6.1 will be installed
---> Package perl-Pod-Simple.x86_64 1:3.13-136.el6_6.1 will be installed
--> Processing Dependency: perl(Pod::Escapes) >= 1.04 for package: 1:perl-Pod-Simple-3.13-136.el6_6.1.x86_64
---> Package perl-libs.x86_64 4:5.10.1-136.el6_6.1 will be installed
---> Package perl-version.x86_64 3:0.77-136.el6_6.1 will be installed
--> Running transaction check
---> Package perl-Pod-Escapes.x86_64 1:1.04-136.el6_6.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                  Arch      Version                    Repository  Size
================================================================================
Installing:
 mysql                    x86_64    5.1.73-3.el6_5             base       894 k
 mysql-server             x86_64    5.1.73-3.el6_5             base       8.6 M
Installing for dependencies:
 mysql-libs               x86_64    5.1.73-3.el6_5             base       1.2 M
 perl                     x86_64    4:5.10.1-136.el6_6.1       updates     10 M
 perl-DBD-MySQL           x86_64    4.013-3.el6                base       134 k
 perl-DBI                 x86_64    1.609-4.el6                base       705 k
 perl-Module-Pluggable    x86_64    1:3.90-136.el6_6.1         updates     40 k
 perl-Pod-Escapes         x86_64    1:1.04-136.el6_6.1         updates     32 k
 perl-Pod-Simple          x86_64    1:3.13-136.el6_6.1         updates    212 k
 perl-libs                x86_64    4:5.10.1-136.el6_6.1       updates    578 k
 perl-version             x86_64    3:0.77-136.el6_6.1         updates     51 k

Transaction Summary
================================================================================
Install      11 Package(s)

Total download size: 23 M
Installed size: 69 M
Downloading Packages:
--------------------------------------------------------------------------------
Total                                           104 kB/s |  23 MB     03:42
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
 Userid : CentOS-6 Key (CentOS 6 Official Signing Key) <[email protected]>
 Package: centos-release-6-6.el6.centos.12.2.x86_64 (@CentOS/$releasever)
 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : mysql-libs-5.1.73-3.el6_5.x86_64                            1/11
  Installing : 1:perl-Pod-Escapes-1.04-136.el6_6.1.x86_64                  2/11
  Installing : 4:perl-libs-5.10.1-136.el6_6.1.x86_64                       3/11
  Installing : 1:perl-Module-Pluggable-3.90-136.el6_6.1.x86_64             4/11
  Installing : 1:perl-Pod-Simple-3.13-136.el6_6.1.x86_64                   5/11
  Installing : 3:perl-version-0.77-136.el6_6.1.x86_64                      6/11
  Installing : 4:perl-5.10.1-136.el6_6.1.x86_64                            7/11
  Installing : perl-DBI-1.609-4.el6.x86_64                                 8/11
  Installing : perl-DBD-MySQL-4.013-3.el6.x86_64                           9/11
  Installing : mysql-5.1.73-3.el6_5.x86_64                                10/11
  Installing : mysql-server-5.1.73-3.el6_5.x86_64                         11/11
  Verifying  : 3:perl-version-0.77-136.el6_6.1.x86_64                      1/11
  Verifying  : perl-DBD-MySQL-4.013-3.el6.x86_64                           2/11
  Verifying  : mysql-libs-5.1.73-3.el6_5.x86_64                            3/11
  Verifying  : mysql-server-5.1.73-3.el6_5.x86_64                          4/11
  Verifying  : mysql-5.1.73-3.el6_5.x86_64                                 5/11
  Verifying  : perl-DBI-1.609-4.el6.x86_64                                 6/11
  Verifying  : 1:perl-Pod-Simple-3.13-136.el6_6.1.x86_64                   7/11
  Verifying  : 4:perl-5.10.1-136.el6_6.1.x86_64                            8/11
  Verifying  : 4:perl-libs-5.10.1-136.el6_6.1.x86_64                       9/11
  Verifying  : 1:perl-Module-Pluggable-3.90-136.el6_6.1.x86_64            10/11
  Verifying  : 1:perl-Pod-Escapes-1.04-136.el6_6.1.x86_64                 11/11 

Installed:
  mysql.x86_64 0:5.1.73-3.el6_5       mysql-server.x86_64 0:5.1.73-3.el6_5      

Dependency Installed:
  mysql-libs.x86_64 0:5.1.73-3.el6_5
  perl.x86_64 4:5.10.1-136.el6_6.1
  perl-DBD-MySQL.x86_64 0:4.013-3.el6
  perl-DBI.x86_64 0:1.609-4.el6
  perl-Module-Pluggable.x86_64 1:3.90-136.el6_6.1
  perl-Pod-Escapes.x86_64 1:1.04-136.el6_6.1
  perl-Pod-Simple.x86_64 1:3.13-136.el6_6.1
  perl-libs.x86_64 4:5.10.1-136.el6_6.1
  perl-version.x86_64 3:0.77-136.el6_6.1                                        

Complete!
 ---> 4ee0c1aacb0e
Removing intermediate container 35ab46137fe7
Successfully built 4ee0c1aacb0

成功创建新的image

-t 定义image属性,属于 hongtu 用户,repository
centos
tag指定为 v2

. 指定在当前目录寻找 Dockerfile

# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
hongtu/centos6      v2                  4ee0c1aacb0e        2 minutes ago       323.1 MB
centos6             hongtu              5f3bca7952ca        31 minutes ago      320.3 MB
centos              centos6             25c5298b1a36        2 weeks ago         215.8 MB

可以看到新建的image id 为 4ee0c1aacb0e

向Docker hub上传 image

# docker push hongtu/centos6

删除本地image

# docker rmi -f hongtu/centos6

-f 强制删除

时间: 2024-10-10 21:40:27

Docker Image操作的相关文章

Docker 之 Docker基础操作

第1章 Docker基础操作 1.1 常用的命令 0) 安装Docker 环境 yum -y install docker 1)   指定 IP,DNS 网络位启动Docker容器 a)  docker -bip 192.168.6.233/28-dns 8.8.8.8 -g /data/docker/  -d 2)   在线pull image 镜像到本地 a)     Docker pull centos 3)   启动容器 a)     Docker run –i –t centos/bi

Docker学习(二)docker镜像操作

上一篇:docker学习(一)在centos7上安装docker 列出所有docker镜像 docker images 拉取镜像 docker pull 镜像名 我这里一Tomact为例 首先在Docker Hub上查找tomcat镜像 搜索tomcat选择收藏和拉取最多的那个,一般就是第一个,然后点击进去通过命令进行拉取 拉取镜像,默认tag: latest最新版本 等待下载完成后,我们就可以在本地镜像列表里查到REPOSITORY为tomcat的镜像. [[email protected]

Docker容器操作

4.Docker容器操作 4.1查看容器 查看正在运行容器: docker ps 查看所有的容器(启动过的历史容器): docker ps –a 查看最后一次运行的容器: docker ps –l 查看停止的容器 docker ps -f status=exited 4.2创建与启动容器 创建容器常用的参数说明: 创建容器命令:docker run -i:表示运行容器 -t:表示容器启动后会进入其命令行.加入这两个参数后,容器创建就能登录进去.即分配一个伪终端. --name :为创建的容器命名

(三) Docker 常用操作与CentOS7 防火墙命令

参考并感谢 Docker 常用命令 https://docs.docker.com/engine/reference/commandline/docker/ Docker 登录docker账户 docker login -u 用户名 -p 密码 根据本地待上传镜像 修改新镜像,新镜像名称需要与hub中的repository保持一致 docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG] 查看所有镜像 docker images 查看特定镜像 docker

Docker 学习笔记【2】 Docker 基础操作实,Docker仓库、数据卷,网络基础学习

Docker 学习笔记[3] Docker 仓库实操,创建私有仓库,实操数据卷.数据卷容器,实操 网络基础  ---------高级网络配置和部分实战案例学习 ============================================================= Docker 学习笔记[1]Docker 相关概念,基本操作--------实操记录开始 ============================================================= 被

docker基础操作

Docker desktop23.example.com 172.25.254.23 Selinx iptables disabled    rhel7.2版本 1.安装 yum install -y docker-engine-1.10.3-1.el7.centos.x86_64.rpm docker-engine-selinux-1.10.3-1.el7.centos.noarch.rpm systemctl start docker 2.简单命令 docker version# 查看版本信

容器技术Docker 容器操作大总结

Docker实战之容器操作: 新建容器: docker create创建的容器处于停止状态,可以使用docker start命令启动Docker容器. 使用docker run命令,可以创建一个运行中的容器. create命令与容器运行模式相关的选项: -a,--attach=[]                                      是否绑定到标准输出.输入和错误 -a,--detach=true|false                              是否在

Docker学习笔记(2)-docker镜像操作

本节将会涉及Docker的镜像操作. 1. 获取镜像 如何获取Docker Hub上的镜像?可通过docker pull命令获取,其格式为: docker pull [选项] [Docker Registry 地址[:端口号]/]仓库名[:标签],具体可通过docker pull --help命令查看. Docker镜像仓库地址的格式一般为<域名/IP>[:端口号],仓库名一般为两段式名称,即<用户名>/<软件名>,对于Docker Hub,默认的用户名为library

Docker 镜像操作

概念 image 镜像: 层叠的只读文件系统,比如有Linux针对于docker而创建的最小的镜像,和其他共享的镜像.简言之就是系统镜像文件.利用面向对象的思想,可以认为image就是一个类,而容器就该类的一个实例. Docker镜像的层次如下: 最底端是一个引导文件系统,即bootfs,这很像典型的Linux/Unix的引导文 件系统.Dockei?用户几乎永远不会和引导文件系统有什么交互.实际上,当一个容器启动 后,它将会被移到内存中,而引导文件系统则会被卸载(unmount),以留出更多的

docker相关操作文章整理

docker整理: 菜鸟教程的nginx操作链接(docker安装完毕安装nginx启动错误,可以看下面的文章) CSDN基于 Docker 安装 Nginx 原文地址:https://www.cnblogs.com/liran123/p/9998614.html