docker常用命令

1、Docker image镜像常用命令

[root@k8s-master01 ~]# docker image 

Usage:  docker image COMMAND

Manage images

Commands:
  inspect     Display detailed information on one or more images
  ls          List images
  pull        Pull an image or a repository from a registry
  rm          Remove one or more images

docker image pull 是下载镜像的命令。镜像从远程镜像仓库服务的仓库中下载,默认从Dcoekr Hub的仓库中拉取。

[root@k8s-master01 ~]# docker image pull alpine:latest
latest: Pulling from library/alpine
59bf1c3509f3: Pull complete 
Digest: sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest

docker image ls 列出本地iDocker主机上存储的镜像。可以通过--digests参数来查看镜像的SHA256签名
[root@k8s-master01 ~]# docker image ls  --digests 
REPOSITORY                                                        TAG                 DIGEST                                                                    IMAGE ID       CREATED         SIZE
alpine                                                            latest              sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300

docker image inspec 展示镜像的细节,包含镜像层数据和元数据
[root@k8s-master01 ~]# docker image inspect alpine:latest 
[
    {
        "Id": "sha256:c059bfaa849c4d8e4aecaeb3a10c2d9b3d85f5165c66ad3a4d937758128c4d18",
        "RepoTags": [
            "alpine:latest"
        ],
        "RepoDigests": [
            "alpine@sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2021-11-24T20:19:40.483367546Z",
        "Container": "4292e8ed2ef2b6dc4bbaf8e1cda0cb5f95b96adc4aa2da3d15181b54d07a0b34",
        "ContainerConfig": {
            "Hostname": "4292e8ed2ef2",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) ",
                "CMD [\"/bin/sh\"]"
            ],
            "Image": "sha256:b747534ae29d08c0c84cc4326caf04e873c6d02bb67cd9c7644be2b4fa8d2f31",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "DockerVersion": "20.10.7",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/sh"
            ],
            "Image": "sha256:b747534ae29d08c0c84cc4326caf04e873c6d02bb67cd9c7644be2b4fa8d2f31",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 5585772,
        "VirtualSize": 5585772,
        "GraphDriver": {
            "Data": {
                "MergedDir": "/var/lib/docker/overlay2/682d9e47cb4d2e812174d3487a06e0bf3321ae106dd893f091f072ded6ae714b/merged",
                "UpperDir": "/var/lib/docker/overlay2/682d9e47cb4d2e812174d3487a06e0bf3321ae106dd893f091f072ded6ae714b/diff",
                "WorkDir": "/var/lib/docker/overlay2/682d9e47cb4d2e812174d3487a06e0bf3321ae106dd893f091f072ded6ae714b/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:8d3ac3489996423f53d6087c81180006263b79f206d3fdec9e66f0e27ceb8759"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]

2、Docker容器

启动容器
docker  run -d  redis:latest

查看容器
[root@k8s-master01 ~]# docker ps |grep redis
a67e8efd5673   redis:alpine                                        "docker-entrypoint.s…"   6 seconds ago   Up 5 seconds           6379/tcp                  

进入到指定的容器
[root@k8s-master01 ~]# docker ps |grep harbor-portal
22abc383a7dd   goharbor/harbor-portal:v2.3.0                       "nginx -g 'daemon of…"   14 months ago   Up 6 weeks (healthy)                                                                                    harbor-portal
[root@k8s-master01 ~]# docker exec -it 2d6deda948a8 /bin/bash
root [ / ]# ls 
bin  boot  dev  etc  home  lib  lib64  media  mnt  proc  root  run  sbin  srv  sys  tmp  usr  var
posted @ 2022-09-17 21:48  老天啊  阅读(47)  评论(0编辑  收藏  举报