Docker 笔记(二)--镜像

Docker 笔记(二)–镜像

记录Docker 安装操作记录,便于查询。

参考

  1. 链接: Docker 入门到实战教程(三)镜像和容器
  2. 链接: docker中daemon.json各配置详解
  3. 链接: docker容器/etc/docker/daemon.json配置文件详解
  4. 链接: docker官方文档

环境

Centos 7.9

操作

1.查看命令

// 查看全部命令
[root@centos7-18 image]# docker command --help 
// 查看某一个命令,例如查看run
[root@centos7-18 image]# docker run --help 

2.查询镜像

// 查询nginx命令
[root@centos7-18 image]# docker search nginx
NAME                               DESCRIPTION                                      STARS     OFFICIAL   AUTOMATED
nginx                              Official build of Nginx.                         19234     [OK]       
unit                               Official build of NGINX Unit: Universal Web …   17        [OK]       
nginxinc/nginx-unprivileged        Unprivileged NGINX Dockerfiles                   133
nginx/nginx-ingress                NGINX and  NGINX Plus Ingress Controllers fo…   86                   
nginx/nginx-prometheus-exporter    NGINX Prometheus Exporter for NGINX and NGIN33                                                      
  • Name:源名称
  • DESCRIPTION:描述
  • STARS:星(点赞)数量
  • OFFICIAL:是否官方发布
  • AUTOMATED:是否自动构建

3.拉取镜像

// 默认拉取最新版
[root@centos7-18 image]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete 
a9edb18cadd1: Pull complete 
589b7251471a: Pull complete 
186b1aaa4aa6: Pull complete 
b4df32aa5a72: Pull complete 
a0bcbecc962e: Pull complete 
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest                                                     

4.查看镜像

4.1. 查看所有镜像

[root@centos7-18 image]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
nginx        latest    605c77e624dd   22 months ago   141MB
redis        latest    7614ae9453d1   23 months ago   113MB                                                 
  • REPOSITORY:表示镜像的仓库源
  • TAG:标签
  • IMAGE ID:ID
  • CREATED:创建时间
  • SIZE:大小
    4.2. 查看镜像详细信息
[root@centos7-18 image]# docker inspect nginx
[
    {
        "Id": "sha256:605c77e624ddb75e6110f997c58876baa13f8754486b461117934b24a9dc3a85",
        "RepoTags": [
            "nginx:latest"
        ],
        "RepoDigests": [
            "nginx@sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2021-12-29T19:28:29.892199479Z",
        "Container": "ca3e48389f7160bc9d9a892d316fcbba459344ee3679998739b1c3cd8e56f7da",
        "ContainerConfig": {
            "Hostname": "ca3e48389f71",
            "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.21.5",
                "NJS_VERSION=0.7.1",
                "PKG_RELEASE=1~bullseye"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) ",
                "CMD [\"nginx\" \"-g\" \"daemon off;\"]"
            ],
            "Image": "sha256:82941edee2f4d17c55563bb926387c3ae39fa1a99777f088bc9d3db885192209",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": [
                "/docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {
                "maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
            },
            "StopSignal": "SIGQUIT"
        },
        "DockerVersion": "20.10.7",
        "Author": "",
        "Config": {
            "Hostname": "",
            "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.21.5",
                "NJS_VERSION=0.7.1",
                "PKG_RELEASE=1~bullseye"
            ],
            "Cmd": [
                "nginx",
                "-g",
                "daemon off;"
            ],
            "Image": "sha256:82941edee2f4d17c55563bb926387c3ae39fa1a99777f088bc9d3db885192209",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": [
                "/docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {
                "maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
            },
            "StopSignal": "SIGQUIT"
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 141479488,
        "VirtualSize": 141479488,
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/8b0be5030647522bf7b1b39db844d8c650bd8133a00ac05b330879de438c0abb/diff:/var/lib/docker/overlay2/563d515cbd4227114e7adeb014737ce26c3238a9e54135141519c5870470a0e0/diff:/var/lib/docker/overlay2/690c4f6a17cb8cf1aabe042511f57c198281895336138ac474117c60a879cc30/diff:/var/lib/docker/overlay2/3de8af079b18dd20b726da9ce7a91836810e1effd694cc39cccfc63925626d2c/diff:/var/lib/docker/overlay2/b04d78c79c57a4b680bf3f66c56a33b683fd632182f630835ec67d3a400ff965/diff",
                "MergedDir": "/var/lib/docker/overlay2/fd8c77083cd9b2c0c9bd36ecf8ade515986d4d9cf536abea70ecb0440fed2907/merged",
                "UpperDir": "/var/lib/docker/overlay2/fd8c77083cd9b2c0c9bd36ecf8ade515986d4d9cf536abea70ecb0440fed2907/diff",
                "WorkDir": "/var/lib/docker/overlay2/fd8c77083cd9b2c0c9bd36ecf8ade515986d4d9cf536abea70ecb0440fed2907/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:2edcec3590a4ec7f40cf0743c15d78fb39d8326bc029073b41ef9727da6c851f",
                "sha256:e379e8aedd4d72bb4c529a4ca07a4e4d230b5a1d3f7a61bc80179e8f02421ad8",
                "sha256:b8d6e692a25e11b0d32c5c3dd544b71b1085ddc1fddad08e68cbd7fda7f70221",
                "sha256:f1db227348d0a5e0b99b15a096d930d1a69db7474a1847acbc31f05e4ef8df8c",
                "sha256:32ce5f6a5106cc637d09a98289782edf47c32cb082dc475dd47cbf19a4f866da",
                "sha256:d874fd2bc83bb3322b566df739681fbd2248c58d3369cb25908d68e7ed6040a6"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]                                               

4.3. 查看镜像中间层

[root@centos7-18 image]# docker images -a                                              

如果不同镜像之间有复用的中间层,这里就会看见一些没有镜像名和标签的镜像,很多镜像依赖这些中间层,所以中间层镜像是不能随意删除的。
4.4. 查看镜像中间层

[root@centos7-18 image]# docker images -a                                              

5.删除镜像

5.1. 删除镜像

// 删除镜像
[root@centos7-18 image]# docker rmi hello-world
// 强制删除镜像  
[root@centos7-18 image]# docker rmi -f hello-world                                         

5.2. 删除虚悬镜像

[root@centos7-18 image]# docker image prune                                      

docker images (不加-a)显示的没有名称和标签的镜像叫虚悬镜像,没有实际用途,可以清除。

6.导出镜像

[root@centos7-18 ~]# docker save -o hello-word.tar hello-world
[root@centos7-18 ~]# ls
anaconda-ks.cfg  hello-word.tar
  • -o 参数后面接着输出文件名。
  • hello-world是需要导出的镜像名。

7.导入镜像

[root@centos7-18 ~]# docker load -i hello-word.tar 
e07ee1baac5f: Loading layer [==================================================>]  14.85kB/14.85kB
Loaded image: hello-world:latest

8.修改镜像名和TAG

[root@centos7-18 ~]# docker tag hello-world:latest hello-world:1.0
[root@centos7-18 ~]# docker tag hello-world:latest hello-demo:1.0
[root@centos7-18 ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
nginx         latest    605c77e624dd   22 months ago   141MB
redis         latest    7614ae9453d1   23 months ago   113MB
hello-demo    1.0       feb5d9fea6a5   2 years ago     13.3kB
hello-world   1.0       feb5d9fea6a5   2 years ago     13.3kB
hello-world   latest    feb5d9fea6a5   2 years ago     13.3kB

9.镜像存储位置

9.1. 存储位置

  • linux保存在“/var/lib/docker/”;
  • windows保存在“C:\ProgramData\DockerDesktop”
  • Mac保存在“com.docker.docker/Data/vms/0/”

9.2. 修改位置
修改镜像存储与运行加载目录

[root@centos7-18 ~]# vim /etc/docker/daemon.json

{
	"data-root": "/data/var/lib/docker",
}
[root@centos7-18 docker]# systemctl daemon-reload 
[root@centos7-18 docker]# systemctl restart docker
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要启动Redis Manager,可以按照以下步骤进行操作: 1. 首先,确保已经安装了Docker,并且已经下载了Redis Manager的Docker镜像。 2. 创建一个目录,用于存放Redis Manager的配置文件和数据。可以使用以下命令创建目录: ``` mkdir /path/to/redis-manager ``` 3. 在创建的目录中,创建一个配置文件redis-manager.conf,并根据需要进行配置。可以参考Redis Manager的官方文档或者使用现有的配置文件作为模板。 4. 使用以下命令启动Redis Manager容器: ``` docker run -p 8081:8081 --name redis-manager -v /path/to/redis-manager/redis-manager.conf:/etc/redis-manager/redis-manager.conf -v /path/to/redis-manager/data:/data -d redis-manager ``` 这个命令会将容器的8081端口映射到主机的8081端口,并将配置文件和数据目录挂载到容器内部。 5. 等待一段时间,Redis Manager容器会启动并运行。可以通过访问http://localhost:8081来访问Redis Manager的Web界面。 请注意,以上步骤中的路径和端口号可以根据实际情况进行修改。同时,确保在启动容器时使用了正确的Docker镜像名称和版本号。 #### 引用[.reference_title] - *1* *2* [Docker 安装 Redis-5.0.12,详细步骤](https://blog.csdn.net/weixin_49343190/article/details/118499260)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [docker学习笔记(四) ——docker启动redis文件并挂载文件](https://blog.csdn.net/qq_42221135/article/details/119650051)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值