Docker:镜像命令和容器命令

下面进入到关于镜像命令的学习中

镜像命令

docker images

这个命令的功能是列出本地的镜像

语法:

docker images [options] [repository[:tag]]

别名:

docker image ls, docker image list

参数选项:

  1. -a:表示列出本地所有镜像
  2. –digests:显示镜像的摘要信息
  3. -f:显示满足条件的镜像
  4. –format:指定返回值的模板文件
  5. –no-trunc:显示完整的镜像信息
  6. -q:只显示镜像id

具体使用:

root@VM-24-7-ubuntu:~# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    d2c94e258dcb   13 months ago   13.3kB

root@VM-24-7-ubuntu:~# docker images ubuntu
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

root@VM-24-7-ubuntu:~# docker images hello-world
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    d2c94e258dcb   13 months ago   13.3kB

docker image inspeact

显示镜像详细信息

docker image inspect [options] image [image...]

使用如下:

root@VM-24-7-ubuntu:~# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    d2c94e258dcb   13 months ago   13.3kB

root@VM-24-7-ubuntu:~# docker image inspect d2c94e258dcb
[
    {
        "Id": "sha256:d2c94e258dcb3c5ac2798d32e1249e42ef01cba4841c2234249495f87264ac5a",
        "RepoTags": [
            "hello-world:latest"
        ],
        "RepoDigests": [
            "hello-world@sha256:266b191e926f65542fa8daaec01a192c4d292bff79426f47300a046e1bc576fd"
        ],
        "Parent": "",
        "Comment": "buildkit.dockerfile.v0",
        "Created": "2023-05-02T16:49:27Z",
        "DockerVersion": "",
        "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": [
                "/hello"
            ],
            "ArgsEscaped": true,
            "Image": "",
            "Volumes": null,
            "WorkingDir": "/",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 13256,
        "GraphDriver": {
            "Data": {
                "MergedDir": "/var/lib/docker/overlay2/ff16204e50b936f729c2efe9e015aa67e27c554d14ddbefdd51cf371bca8341d/merged",
                "UpperDir": "/var/lib/docker/overlay2/ff16204e50b936f729c2efe9e015aa67e27c554d14ddbefdd51cf371bca8341d/diff",
                "WorkDir": "/var/lib/docker/overlay2/ff16204e50b936f729c2efe9e015aa67e27c554d14ddbefdd51cf371bca8341d/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:ac28800ec8bb38d5c35b49d45a6ac4777544941199075dff8c4eb63e093aa81e"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]

docker tag

标记本地镜像,将其归入某一仓库

docker tag source_image[:tag] target_image[:tag]

别名:

docker image tag

样例:

root@VM-24-7-ubuntu:~# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    d2c94e258dcb   13 months ago   13.3kB

root@VM-24-7-ubuntu:~# docker image tag hello-world myregistry.com/myhelloworld

容器命令

docker run

功能:创建一个新的容器并运行一个命令

docker run [options] image [command] [arg...]

例如:

docker container run

具体使用:

使用Docker镜像nginx:lastest在后台模式启动一个容器,并把容器命名为mynginx:

root@VM-24-7-ubuntu:~# docker run --name mynginx -d nginx:latest
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
09f376ebb190: Pull complete 
5529e0792248: Pull complete 
9b3addd3eb3d: Pull complete 
57910a8c4316: Pull complete 
7b5f78f21449: Pull complete 
b7923aa4e8a6: Pull complete 
785625911f12: Pull complete 
Digest: sha256:0f04e4f646a3f14bf31d8bc8d885b6c951fdcf42589d06845f64d18aec6a3c4d
Status: Downloaded newer image for nginx:latest
3c6ab83484c462da21a583eedd8d2544858034de6f30ada9eac1d10c6779b791

使用镜像nginx:lastest,以后台模式启动一个容器,把容器的80端口映射到主机的80端口,主机的目录/data映射到容器的/data

docker run -p 80:80 -v /data:/data -d nginx:latest

docker ps

功能:列出容器

docker ps

别名:

docker container ls
docker container list
docker container ps

实例:

root@VM-24-7-ubuntu:~# docker ps -a
CONTAINER ID   IMAGE          COMMAND                  CREATED              STATUS                         PORTS     NAMES
3c6ab83484c4   nginx:latest   "/docker-entrypoint.…"   About a minute ago   Up About a minute              80/tcp    mynginx
b9c61a19414e   hello-world    "/hello"                 About an hour ago    Exited (0) About an hour ago             upbeat_swartz

相关推荐

  1. Docker镜像命令容器命令

    2024-06-09 17:34:01       22 阅读
  2. docker学习--docker容器镜像常用命令大全(简)

    2024-06-09 17:34:01       17 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-09 17:34:01       5 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-09 17:34:01       5 阅读
  3. 在Django里面运行非项目文件

    2024-06-09 17:34:01       4 阅读
  4. Python语言-面向对象

    2024-06-09 17:34:01       7 阅读

热门阅读

  1. Spring boot SSL证书路径配置

    2024-06-09 17:34:01       18 阅读
  2. MyBatis 延迟加载,一级缓存,二级缓存设置

    2024-06-09 17:34:01       22 阅读
  3. 在 Linux 系统上安装 Android NDK

    2024-06-09 17:34:01       20 阅读
  4. Redis的哨兵机制,一文全解

    2024-06-09 17:34:01       13 阅读
  5. 07.组件间通信-provide-inject(祖孙通信)

    2024-06-09 17:34:01       24 阅读
  6. 常见知识点总结

    2024-06-09 17:34:01       18 阅读
  7. 列表的C++实

    2024-06-09 17:34:01       20 阅读
  8. JZ2440笔记:热插拔驱动

    2024-06-09 17:34:01       15 阅读
  9. 相同的树-力扣

    2024-06-09 17:34:01       24 阅读
  10. TypeScript常见面试题第十一节

    2024-06-09 17:34:01       13 阅读
  11. TalkingData数据统计:洞察数字世界的关键工具

    2024-06-09 17:34:01       17 阅读