zoukankan      html  css  js  c++  java
  • docker3-镜像的使用

     基本使用命令:

    [root@ipha-dev71-1 docker]# docker search python    # 搜索镜像
    [root@ipha-dev71-1 docker]# docker pull centos/python-36-centos7   # 下载镜像
    [root@ipha-dev71-1 docker]# docker images    # 镜像查看(以下字段对应:仓库名称 版本号 镜像ID 创建时间 )
    REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
    centos/python-36-centos7   latest              046b1b132fcb        4 days ago          717MB
    hello-world                latest              fce289e99eb9        8 months ago        1.84kB
    training/webapp            latest              6fae60ef3446        4 years ago         349MB
    [root@ipha-dev71-1 docker]# docker rmi hello-world:latest   # 删除镜像
    [root@ipha-dev71-1 home]# docker save -o /home/docker_dir/python.tar centos/python-36-centos7  # 镜像保存,-o是指定写入的文件名和路径
    [chenjl@ipha-dev71-1 docker_dir]$ ll
    total 729264
    -rw------- 1 root root 746766336 Sep 17 11:33 python.tar
    docker rmi -f 容器id      # 强制删除镜像
    docker image prune # 批量删除未使用的容器

    创建镜像:

    1.从 Docker Hub 网站来搜索镜像,Docker Hub 网址为: https://hub.docker.com/  (就是上述介绍)

    2.从已经创建的容器中更新镜像,并且提交这个镜像

    3.使用 Dockerfile 指令来创建一个新的镜像

    更新镜像:

    [root@ipha-dev71-1 chenjl]# docker run -t -i ubuntu:14.04 /bin/bash  # -t指定版本 -i进入交互模式
    root@f24c1984b49a:/# exit  # 退出容器(退出交互模式)
    [root@ipha-dev71-1 chenjl]# docker commit -m="has update" -a="mengmeng" f24c1984b49a mengmeng/ubuntu:v2  # -m是备注,-a是作者
    sha256:0963e6b707d98b04a43d6b9641479dce221db063dbe3f22f8482869e7dec834d
    [root@ipha-dev71-1 chenjl]# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    mengmeng/ubuntu     v2                  0963e6b707d9        7 seconds ago       188MB
    更新镜像

    构建镜像:

    [root@ipha-dev71-1 test]# pwd
    /home/docker_dir/test
    [root@ipha-dev71-1 test]# ll
    total 4
    -rw-r--r-- 1 root root 41 Sep 22 11:15 Dockerfile    
    [root@ipha-dev71-1 test]# cat Dockerfile 
    FROM ubuntu:latest
    CMD echo hello world!
    [root@ipha-dev71-1 test]# docker build -t test-ubuntu:v1 .     # 构建时指定版本
    Sending build context to Docker daemon  2.048kB
    Step 1/2 : FROM ubuntu:latest
    latest: Pulling from library/ubuntu
    5667fdb72017: Pull complete 
    d83811f270d5: Pull complete 
    ee671aafb583: Pull complete 
    7fc152dfb3a6: Pull complete 
    Digest: sha256:b88f8848e9a1a4e4558ba7cfc4acc5879e1d0e7ac06401409062ad2627e6fb58
    Status: Downloaded newer image for ubuntu:latest
     ---> 2ca708c1c9cc
    Step 2/2 : CMD echo hello world!
     ---> Running in 589a93408461
    Removing intermediate container 589a93408461
     ---> 37c9cfa35a08
    Successfully built 37c9cfa35a08
    Successfully tagged test-ubuntu:v1
    [root@ipha-dev71-1 test]# docker build -t test-ubuntu:v1 .     # 可以看到第二次构建快速很多,由于是从缓存中读的数据
    Sending build context to Docker daemon  2.048kB
    Step 1/2 : FROM ubuntu:latest
     ---> 2ca708c1c9cc
    Step 2/2 : CMD echo hello world!
     ---> Using cache
     ---> 37c9cfa35a08
    Successfully built 37c9cfa35a08
    Successfully tagged test-ubuntu:v1

    接上:

    [root@ipha-dev71-1 test]# docker images  # 查看构建的镜像
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    test-ubuntu         v1                  37c9cfa35a08        3 minutes ago       64.2MB
    mengmeng/ubuntu     v2                  0963e6b707d9        14 minutes ago      188MB
    12306_ticket        latest              ddc31ea56cd9        11 hours ago        1.84GB
    <none>              <none>              d5857c982bb6        2 days ago          924MB
    ubuntu              latest              2ca708c1c9cc        3 days ago          64.2MB
    ubuntu              14.04               2c5e00d77a67        4 months ago        188MB
    hello-world         latest              fce289e99eb9        8 months ago        1.84kB
    training/webapp     latest              6fae60ef3446        4 years ago         349MB
    [root@ipha-dev71-1 test]# docker run 37c9cfa35a08  # 启动构建的镜像(只在第一次运行时使用,其余使用docker start)
    hello world!
  • 相关阅读:
    串一串《数学之美》中的信息论的几个章节
    失败经历--在windows下安装meld
    xv6实验环境搭建
    python爬取网站数据
    零散知识
    Pycharm使用技巧
    变量
    电信光猫强制wifi(SSID)名称ChinaNet开头解决办法之一
    PhpStorm 常用快捷键
    Android Studio 安装与使用ADB wifi 无线调试
  • 原文地址:https://www.cnblogs.com/wang-mengmeng/p/11566232.html
Copyright © 2011-2022 走看看