二.docker镜像基本命令



 

  1. 获取镜像:

    docker pull cenos

  1. 查看镜像:

    [root@bogon ~]# docker images

    REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

    centos              latest              d83a55af4e75        8 days ago          196.7 MB

  2. docker镜像添加新标签

    [root@bogon ~]# docker tag centos:latest cenos:later

    [root@bogon ~]# docker images

    REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

    centos              latest              d83a55af4e75        8 days ago          196.7 MB

    cenos               later               d83a55af4e75        8 days ago          196.7 MB

  3. 获取镜像的详细信息:

    [root@bogon ~]# docker inspect d83a55af4e75

    [

    {

        "Id": "d83a55af4e75f89d589940a008e1f8d87329fed8e88b17519b07bafee796e0c7",

        "Parent": "3fbd5972aaac8678641224de872b186ee11e8da3bfec293715b256e1ab4db14e",

        "Comment": "",

        "Created": "2016-07-29T20:59:10.01570692Z",

        "Container": "53ef97a96c409a033e214be92d67d0682ecace7ae5155c647a80aea20fb8e375",

  4. 查询指定信息

    [root@bogon ~]# docker inspect -f {{.Architecture}} d83a55af4e75

    amd64

  5. 搜寻镜像

    [root@bogon ~]# docker search mysql

    NAME                    DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED

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

    mariadb                 MariaDB is a community-developed fork of M...   787       [OK]       

     

    7.使用镜像ID删除镜像

    [root@bogon ~]# docker rmi d83a55af4e75

    Untagged: centos:latest

    Deleted: d83a55af4e75f89d589940a008e1f8d87329fed8e88b17519b07bafee796e0c7

    Deleted: 3fbd5972aaac8678641224de872b186ee11e8da3bfec293715b256e1ab4db14e

    Deleted: b200b2d33d98732d2487f455e0851f2cb09dfae28fd3055ea6d401ff9e8df3da

    Deleted: 3690474eb5b4b26fdfbd89c6e159e8cc376ca76ef48032a30fa6aafd56337880

  1. docker创建第一个容器:

    [root@bogon ~]# docker run centos echo 'hello world'

    hello world

  2. 查看机器上的所有容器

    root@bogon ~]# docker ps -a

    CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                      PORTS               NAMES

    98790c7a70e0        centos              "echo 'hello world'"   26 seconds ago      Exited (0) 24 seconds ago                       cranky_darwin

     

  3. 强行删除镜像

    Docker rmi -f centod

  4. 创建镜像

  1. 基于已有镜像的容器创建

    a启动一个镜像进行一些修改操作,退出

    [root@bogon ~]# docker run -ti centos:latest /bin/bash

    [root@5f3e0f1a69bb /]# touch test

    [root@5f3e0f1a69bb /]# exit

    Exit

    b.提交镜像

    [root@bogon ~]# docker commit -m "ADdd a new file" -a  "Docker Newbee"  5f3e0f1a69bb  test

    1d7be5e364c1fa25f686543fa2c0df507c039c0d46ac4d7501a6955307b5ee3a

    [root@bogon ~]# docker images

    REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

    test                latest              1d7be5e364c1        14 seconds ago      196.7 MB

    centos              latest              d83a55af4e75        8 days ago          196.7 MB

     

  2. 基于本地模板导入

    [root@bogon Desktop]# cat MySQL-python-1.2.2.tar.gz  | docker import -  mysqlpython:1.2.2

    6455db1ee110d30e0dffe0f875778e65c317510b4e98453281b7e29aab476421

     

  3. 基于dockerfile创建

  1. 存入存出镜像

  1. 存出镜像

    [root@bogon Desktop]# docker images

    REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

    mysqlpython         1.2.2               6455db1ee110        3 minutes ago       323.2 kB

    cenos               1.2.2               8805a9541c19        3 minutes ago       323.2 kB

    test                latest              1d7be5e364c1        17 minutes ago      196.7 MB

    centos              latest              d83a55af4e75        8 days ago          196.7 MB

    [root@bogon Desktop]# docker save -o mysql-python_1.2.2  mysqlpython:1.2.2

    [root@bogon Desktop]# ls

    mysql-python_1.2.2  MySQL-python-1.2.2.tar.gz  python

     

  2. 载入镜像

    [root@bogon Desktop]# docker load < mysql-latest.tar.xz

    或者[root@bogon Desktop]# docker load --input mysql-latest.tar.xz

    13.上传镜像

    docker push user/test:latest(user用户需要在dockerHub网站注册)

你可能感兴趣的:(系统运维)