Docker 使用方法总结之:镜像

  1. 查找

    命令:docker search [OPTIONS] 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

    例子:

    [[email protected] ~]# docker search mysql

    NAME                         DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED

    mysql                        MySQL is a widely used, open-source relati...   655       [OK]

    tutum/mysql                  MySQL Server image - listens in port 3306....   115                  [OK]

    orchardup/mysql                                                              37                   [OK]

    centurylink/mysql            Image containing mysql. Optimized to be li...   21                   [OK]

    ...................

  2. 获取

    命令:docker pull [OPTIONS] NAME[:TAG]

    参数:  -a, --all-tags=false    Download all tagged images in the repository

    例子:

    [[email protected] ~]# docker pull tutum/mysql

    Pulling repository tutum/mysql

    26c0c52dc79a: Pulling dependent layers

    511136ea3c5a: Download complete

    27d47432a69b: Download complete

    5f92234dcf1e: Download complete

    51a9c7c1f8bb: Download complete

    5ba9dab47459: Download complete

    d26d9affc74e: Download complete

    c8420faa4614: Download complete

    .........

  3. 运行image

    命令:docker run -t -i tutum/mysql /bin/bash

  4. 查看列表

    命令:docker images [OPTIONS] [NAME]

    参数

    -a, --all=false      Show all images (by default filter out the intermediate image layers)

    -f, --filter=[]      Provide filter values (i.e. ‘dangling=true‘)

    --no-trunc=false     Don‘t truncate output

    -q, --quiet=false    Only show numeric IDs

    例子

    [[email protected] ~]# docker images -a

    REPOSITORY            TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

    <none>                <none>              6941bfcbbfca        10 days ago         0 B

    eric/ubuntu           latest              52671e55fb86        6 weeks ago         270.3 MB

    <none>                <none>              c8420faa4614        3 months ago        192.7 MB

    <none>                <none>              d26d9affc74e        3 months ago        192.7 MB

    <none>                <none>              5ba9dab47459        3 months ago        192.7 MB

  5. 更改TAG

    更改之前:

    [[email protected] ~]# docker images

    REPOSITORY            TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

    centos                7                   fd44297e2ddb        10 days ago         229.6 MB

    centos                centos7             fd44297e2ddb        10 days ago         229.6 MB

    centos                latest              fd44297e2ddb        10 days ago         229.6 MB

    eric/ubuntu           latest              52671e55fb86        6 weeks ago         270.3 MB

    tutum/mysql           latest              26c0c52dc79a        3 months ago        322.5 MB

    centos_6_5            ansible             f01c1b138488        10 months ago       322.4 MB

    chug/ubuntu12.10x64   latest              0b96c14dafcd        13 months ago       270.3 MB

    执行命令:

    docker tag tutum/mysql:latest localrepo:newtag

    更改之后:

    [[email protected] ~]# docker images

    REPOSITORY            TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

    centos                7                   fd44297e2ddb        10 days ago         229.6 MB

    centos                centos7             fd44297e2ddb        10 days ago         229.6 MB

    centos                latest              fd44297e2ddb        10 days ago         229.6 MB

    eric/ubuntu           latest              52671e55fb86        6 weeks ago         270.3 MB

    tutum/mysql           latest              26c0c52dc79a        3 months ago        322.5 MB

    localrepo             newtag              26c0c52dc79a        3 months ago        322.5 MB

    centos_6_5            ansible             f01c1b138488        10 months ago       322.4 MB

    chug/ubuntu12.10x64   latest              0b96c14dafcd        13 months ago       270.3 MB

  6. 查看明细

    命令:docker inspect [OPTIONS] CONTAINER|IMAGE [CONTAINER|IMAGE...]

    参数:-f, --format=""    Format the output using the given go template.

    例子:

    [[email protected] ~]# docker inspect f01c1b138488

  7. 删除

    命令:docker rmi [OPTIONS] IMAGE [IMAGE...]

    参数:

    -f, --force=false    Force removal of the image

    --no-prune=false     Do not delete untagged parents

    例子:

    [[email protected] ~]# docker rmi 26c

    Error response from daemon: Conflict, cannot delete 26c0c52dc79a because the container 002ca178e599 is using it, use -f to force

    上面出错的原因是因为该镜像正在被002ca178e599的容器使用,所以不能删除,所以首先需要使用docker rm删除容器,然后再删除,相关的AUFS文件也会被删除

    [[email protected] ~]# docker rm 002

    002

    [[email protected] ~]# docker rmi 26c

    Untagged: localrepo:newtag

    Deleted: 26c0c52dc79af8acf07a18cd1693bfae91926f496ee4d1c1dbe29a014394b7c0

    Deleted: ba600267bf1a82675eeee78a2e18c49306c46888ca3cf33f372be4b80334d4f0

    Deleted: 6d79a1795e744a9c2c4409526f90c9711d96d0e944a7f485fc31acf7e44fb210

    Deleted: cb6a06a808d4329b1bba405b9e3e733b1c379fb55979e8631e918f6c14c6023a

    Deleted: 8d466d27bccad3502d579a2e0e6fc28fa8a46e32b5b453e7387a61eef7c1be8a

    ......

  8. 创建

    由于

    1. 基于Container创建

      1. 启动一个容器

        [[email protected] ~]# docker run -ti f01 /bin/bash

      2. 在启动的容器中安装ansible,git等工具
      3. 查询Container ID

        [[email protected] ~]# docker ps

        CONTAINER ID        IMAGE                COMMAND             CREATED             STATUS              PORTS               NAMES

        52ec71824717        centos_6_5:ansible   "/bin/bash"         31 seconds ago      Up 30 seconds                           high_mcclintock

      4. 执行创建命令,返回值就是生成的Image ID

        [[email protected] ~]# docker commit -m ‘Ansible Image,and git, sample yml files‘ -a ‘Eric.sunah‘ 52ec71824717 eric/ansible

        6e3832e7c6e1aba47aefe1430c346a1dbf9a0454c37a907d293eaf7056d11d91

      5. 查看新的列表

        [[email protected] ~]# docker images

        REPOSITORY            TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

        eric/ansible          latest              6e3832e7c6e1        2 minutes ago       629.7 MB

        eric/ubuntu           latest              52671e55fb86        6 weeks ago         270.3 MB

        centos_6_5            ansible             f01c1b138488        10 months ago       322.4 MB

        chug/ubuntu12.10x64   latest              0b96c14dafcd        13 months ago       270.3 MB

  9. 另存为

    命令:docker save [OPTIONS] IMAGE [IMAGE...]

    参数:  -o, --output=""    Write to a file, instead of STDOUT

    例子:

    docker save -o centos6_ansible.tar eric/ansible

  10. 导入

    命令:docker load [OPTIONS]

    参数:   -i, --input=""     Read from a tar archive file, instead of STDIN

    例子:

    docker load --input centos6_ansible.tar

  11. 上传

    首先取个便于识别的TAG

    [[email protected] ~]# docker tag 6e38 sun7545526/template:ansible

    [[email protected] ~]# docker images

    REPOSITORY            TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

    sun7545526/template   ansible             6e3832e7c6e1        17 minutes ago      629.7 MB

    eric/ansible          latest              6e3832e7c6e1        17 minutes ago      629.7 MB

    执行上传命令,第一次上传的时候会要求输入用户名,密码,邮箱信息:

    [[email protected] ~]# docker push sun7545526/template:ansible

    The push refers to a repository [sun7545526/template] (len: 1)

    Sending image list

    Pushing repository sun7545526/template (1 tags)

    511136ea3c5a: Image already pushed, skipping

    1d6ebc5c68b1: Image already pushed, skipping

    f01c1b138488: Image already pushed, skipping

    6e3832e7c6e1: Image successfully pushed

    Pushing tag for rev [6e3832e7c6e1] on {https://cdn-registry-1.docker.io/v1/repositories/sun7545526/template/tags/ansible}

时间: 2025-01-12 08:26:39

Docker 使用方法总结之:镜像的相关文章

Docker系列(一)---镜像

本系列实验环境均为:CentOS6.6 使用epel库安装docker [[email protected]~]# rpm -ivh http://mirrors.sohu.com/fedora-epel/6/i386/epel-release-6-8.noarch.rpm [[email protected]~]# yum install docker-io -y 启动docker并设为开机自启 [[email protected]~]# /etc/init.d/dockerstart [[e

docker 实战---安装一个基础镜像 (一)

泡了几天官网,对docker有了一点了解.准备着手搭建一个公司的开发测试环境,包括java.python. 环境介绍 首先说明一下我的环境 2台物理服务器(后面简称主机) 主机A的配置如下: [[email protected] ~]# lsb_release -a LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:p

Docker中通过模板创建镜像,Docker容器、仓库及数据管理

1.通过模板创建镜像 (1)首先去下载一个模板 http://openvz.org/Download/templates/precreated //下载速度不快,阿铭下载了一个centos6的模板centos-6-x86-minimal.tar.gz (2)导入该镜像的命令为: cat centos-6-x86-minimal.tar.gz|docker import - centos6 (3)查看导入的镜像 docker images (4)导出镜像: 把现有镜像,导出为一个文件: docke

Docker基础命令详解——镜像及容器操作

Docker基础命令详解--镜像及容器操作 前言 ? 上篇文章介绍了有关Docker的基础与Linux下docker的安装,本文主要讲解安装docker后的基础使用方法以及命令的介绍,主要是docker镜像操作及容器操作命令. ? 当然,docker的相关命令非常多,可以使用docker help命令查看对应目录以及相关提示命令. Docker镜像操作命令 [[email protected] ~]# which docker /usr/bin/docker 1.镜像搜索:docker sear

使用docker构建、运行jenkins镜像

目录: 1.基于docker官方的jenkins镜像启动容器 2.使用源码构建jenkins镜像并运行容器 3.使用csphere产品对容器.镜像.主机进行管理 docker近两年很火,最近在听cSphere希云主办的docker培训, 之前也参加过docker相关的技术沙龙(如docker meetup). 同时也使用Jenkins近两年,所以尝试使用docker构建jenkins镜像.运行基于镜像的容器. 因为听希云的docker培训获得了一张200元的腾讯云代金券, 所以用代金券在腾讯云上

docker 存出,载入镜像

docker save XXXXXX存出镜像,随意拷贝分享给他人,这个导出的是一个XXXXX.tar文件 载入镜像:docker load --input XXXXX.tar

在Ubuntu升级Docker的方法

摘要:在文章<体验DigitalOcean的VPS云服务>中实现了搭建一个Ubuntu 14.04的VPS操作系统环境,并使用Ubuntu 14.04版本官方软件源中已经自带的Docker包(docker.io)完成了Docker的安装,但是安装后的版本为1.0.1比较老,一些新的功能无法使用(比如,docker exec),本文记录升级到最新Docker的方法. 第一次的安装方法:(apt-get) apt-get install -y docker.io ln -sf /usr/bin/d

Docker基础-使用Dockerfile创建镜像

1.基本结构 Dockerfile由一行行命令语句组成,并支持以#开头的注释行.例如: # This dockerfile uses the ubuntu image # VERSION 2 - EDITION 1 # Author: docker_user # Command format: Instruction [arguments / command ] .. # Base image to use, this nust be set as the first line FROM ubu

Docker系列(二)镜像管理

2.1 查看镜像 [[email protected] ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/hello-world latest 05a3bd381fc2 5 weeks ago 1.84 kB 选项说明:REPOSTITORY:表示镜像的仓库源TAG:镜像的标签IMAGE ID:镜像IDCREATED:镜像创建时间SIZE:镜像大小同一仓库源可以有多个 TAG,代表这个仓库源的不同个版本,如ubunt

使用docker Registry快速搭建私有镜像仓库

当我们执行docker pull xxx的时候,docker默认是从registry.docker.com这个地址上去查找我们所需要的镜像文件,然后执行下载操作.这类的镜像仓库就是docker默认的公共仓库,所有人都可以直接查看或下载.使用,但是呢,基于网络原因,下载速度有限制比较慢.因此,我们在公司内部内网环境中使用dokcer,一般不会将镜像文件上传到公网公共库中.但内部共享使用就是个问题,所以,私有仓库就由此产生了. 什么是私有仓库? 私有仓库,就是本地(内网环境)组建的一个与公网公共库功