zoukankan      html  css  js  c++  java
  • 三、docker的镜像操作

    docker的镜像操作

    一、搜索docker镜像

    1、搜索官方镜像

    [root@inode3 ~]# docker search nginx

    使用官方镜像建议选这OFFICIAL或者STARS星多的镜像

    2、在第三方网站搜索镜像文件

    https://hub.docker.com/

    二、docker镜像下载

    获取镜像
    docker pull nginx
    docker pull centos:6.9
    如果在获取镜像时,没有指定版本,默认是最新版本。如:nginx:latest   centos:latest(现在centos最新为centos8)

    如下pull一个centos6.9的镜像

    [root@inode3 ~]# docker pull centos:6.9
    6.9: Pulling from library/centos
    831490506c47: Pull complete 
    Digest: sha256:6fff0a9edc920968351eb357c5b84016000fec6956e6d745f695e5a34f18ecd2
    Status: Downloaded newer image for centos:6.9
    docker.io/library/centos:6.9

    三、docker镜像的查看

    查看当前本地有些什么镜像文件
    [root@inode3 ~]# docker images 
    [root@inode3 ~]# docker image ls 

    四、docker镜像文件的导出

    1、导出单个镜像文件

    导出nginx的镜像文件到/mnt下
    [root@inode3 ~]# docker image save nginx:latest > /mnt/docker_nginx.tar.gz
    [root@inode3 ~]# ll /mnt
    total 127492
    -rw-r--r-- 1 root root 130548224 Mar  4 16:54 docker_nginx.tar.gz

    2、同时导出多个镜像文件为一个文件

    同时导出nginx和centos6.9
    [root@inode3 ~]# docker image save -o /mnt/docker_nginx_centos.tar.gz nginx:latest centos:6.9
    [root@inode3 ~]# ll /mnt
    total 452660
    -rw------- 1 root root 332968448 Mar  4 16:57 docker_nginx_centos.tar.gz
    -rw-r--r-- 1 root root 130548224 Mar  4 16:54 docker_nginx.tar.gz

    五、删除镜像文件

    删除nginx镜像文件
    [root@inode3 ~]# docker image rm nginx:latest

    六、镜像导入

    重新导入nginx镜像文件
    [root@inode3 ~]# docker image load -i /mnt/docker_nginx.tar.gz 
    f2cb0ecef392: Loading layer  72.48MB/72.48MB
    fe08d5d042ab: Loading layer  58.04MB/58.04MB
    318be7aea8fc: Loading layer  3.584kB/3.584kB
    Loaded image: nginx:latest
    
    删除nginx和centos6.9的镜像,导入刚才导出的docker_nginx_centos.tar.gz
    [root@inode3 ~]# docker image ls
    REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
    ansible/centos7-ansible   latest              688353a31fde        3 years ago         447MB
    
    镜像导入
    [root@inode3 ~]# docker image load -i /mnt/docker_nginx_centos.tar.gz 
    f2cb0ecef392: Loading layer [==========================================>] 72.48MB/72.48MB
    fe08d5d042ab: Loading layer [==========================================>] 58.04MB/58.04MB
    318be7aea8fc: Loading layer [==========================================>] 3.584kB/3.584kB
    Loaded image: nginx:latest
    aaa5621d7c01: Loading layer [==========================================>] 202.4MB/202.4MB
    Loaded image: centos:6.9
    
    [root@inode3 ~]# docker image ls
    REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
    nginx                     latest              a1523e859360        6 days ago          127MB
    centos                    6.9                 2199b8eb8390        11 months ago       195MB
    ansible/centos7-ansible   latest              688353a31fde        3 years ago         447MB

    七、查看镜像信息

    [root@inode3 ~]# docker image inspect nginx:latest
    [
        {
            "Id": "sha256:a1523e859360df9ffe2b31a8270f5e16422609fe138c1636383efdc34b9ea2d6",
            "RepoTags": [
                "nginx:latest"
            ],
            "RepoDigests": [],
            "Parent": "",
            "Comment": "",
            "Created": "2020-02-26T20:02:15.724396212Z",
            "Container": "a7e44d480f0a875093e5f531cae42c2f24fc277d2ba4089fd8464f25eda77825",
            "ContainerConfig": {
                "Hostname": "a7e44d480f0a",
                "Domainname": "",
                "User": "",
                "AttachStdin": false,
                "AttachStdout": false,
                "AttachStderr": false,
                "ExposedPorts": {
                    "80/tcp": {}
                },
                "Tty": false,
                "OpenStdin": false,
                "StdinOnce": false,
                "Env": [
                    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                    "NGINX_VERSION=1.17.8",
                    "NJS_VERSION=0.3.8",
                    "PKG_RELEASE=1~buster"
                ],
                "Cmd": [
                    "/bin/sh",
                    "-c",
    .....

    八、更改镜像的名称

    格式:docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
    
    [root@inode3 ~]# docker tag  nginx:latest nginx_1:v1
    [root@inode3 ~]# docker image ls
    REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
    nginx                     latest              a1523e859360        6 days ago          127MB
    nginx_1                   v1                  a1523e859360        6 days ago          127MB
    centos                    6.9                 2199b8eb8390        11 months ago       195MB
    ansible/centos7-ansible   latest              688353a31fde        3 years ago         447MB

    九、镜像加速

    由于众所周知的原因,国内从 Docker Hub 拉取镜像速度缓慢,甚至中断,此时可以配置Docker加速器(国内镜像)来解决此问题。国内很多云服务商都提供了国内加速器服务,主要分为两种,一种需要创建登录账号,另一种则不需要创建登录账号。

    需要登录账号

    大致等同于阿里云的Docker加速器,主要环节也就是以下三步:
    
    1. 注册账号,获得专属的镜像加速地址。
    2. 根据提示和系统类型,升级、配置并重启Docker。
    3. 实际操作,验证配置是否正确。

    不需要登录账号(支持匿名pull)

    对于使用systemd的系统(Ubuntu 16.04+、Debian 8+、CentOS 7+),可以创建 /etc/docker/daemon.json文件,并写入如下内容:

    cat >> /etc/docker/daemon.json <<EOF
    {
      "registry-mirrors": [
        "https://dockerhub.azk8s.cn",
        "https://docker.mirrors.ustc.edu.cn",
        "https://registry.docker-cn.com"
      ]
    }
    EOF
    #可以同时配置多个镜像加速器,加速器之间需要使用","分离
    #重启docker
    systemctl daemon-reload
    systemctl restart docker
    一些支持匿名pull的国内镜像
    Docker-CN: https://registry.docker-cn.com
    中科大镜像: https://docker.mirrors.ustc.edu.cn
    Azure中国镜像: https://dockerhub.azk8s.cn

    阿里云的docker镜像加速器需要去阿里云官网申请账号,在产品与服务---弹性计算---容器镜像服务---镜像加速器

  • 相关阅读:
    802.11标准及无线网运行模式
    linux中top命令使用及查看tcp连接
    DNS信息收集命令nslookup
    Openvas安装
    nc高级应用
    poj 1411 Calling Extraterrestrial Intelligence Again(超时)
    poj 1046 Color Me Less
    1215 迷宫
    2666 Accept Ratio(打表AC)
    2021 中庸之道
  • 原文地址:https://www.cnblogs.com/yaokaka/p/14177370.html
Copyright © 2011-2022 走看看