首页 > 其他分享 >docker基础命令

docker基础命令

时间:2024-12-26 09:26:42浏览次数:6  
标签:ago nginx months 基础 命令 镜像 docker root

docker基础命令

文章目录

docker pull 拉取镜像

在渡渡鸟镜像站 :https://docker.aityp.com/

[root@cwf ~]# docker pull swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx:mainline-alpine3.18-perl

docker images 显示镜像列表

[root@cwf ~]# docker images
REPOSITORY                                                 TAG                        IMAGE ID       CREATED        SIZE
swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx   mainline-alpine3.18-perl   5d0cd28768c1   7 months ago   78.1MB
[root@cwf ~]#  

显示所有镜像

使用选项 -a (--all) 列出本地所有镜像(含中间镜像层)
[root@cwf ~]# docker images -a
REPOSITORY                                                 TAG                        IMAGE ID       CREATED        SIZE
swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx   mainline-alpine3.18-perl   5d0cd28768c1   7 months ago   78.1MB
[root@cwf ~]# docker images --all
REPOSITORY                                                 TAG                        IMAGE ID       CREATED        SIZE
swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx   mainline-alpine3.18-perl   5d0cd28768c1   7 months ago   78.1MB
[root@cwf ~]# 

调整镜像信息

选项 --no-trunc 表示显示完整的镜像信息
[root@localhost ~]# docker images --no-trunc
REPOSITORY                                                                       TAG           IMAGE ID                                                                  CREATED        SIZE
swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginxinc/nginx-unprivileged   1.27-alpine   sha256:5b7e2ee8c78d7a7d8410785cb72824a01e52605d2c15b38d0f8da54c8a0ce975   2 months ago   47MB
httpd                                                                            bookworm      sha256:bfe6700e67790a2c4a4ea7e55bf2ce823764a6c9f76d512418ed8a60bf8f1526   8 months ago   147MB
swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/httpd                         bookworm      sha256:bfe6700e67790a2c4a4ea7e55bf2ce823764a6c9f76d512418ed8a60bf8f1526   8 months ago   147MB
选项 -q (--quiet) 表示只要显示镜像ID
[root@cwf ~]# docker images -q
5d0cd28768c1
[root@cwf ~]# docker images --quiet
5d0cd28768c1
使用 --digests 选项将镜像的摘要显示出来
[root@cwf ~]# docker images --digests
REPOSITORY                                                 TAG                        DIGEST                                                                    IMAGE ID       CREATED        SIZE
swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx   mainline-alpine3.18-perl   sha256:961005a67cf19ad3af9fdd8ac1866371b024bf4dfc762490aa64ec9da1d47fbe   5d0cd28768c1   7 months ago   78.1MB

显示镜像列表

.ID:镜像ID。
.Repository:镜像仓库名称。
.Tag:镜像标签。
.Digest:镜像摘要。
.CreatedSince:镜像创建以来的时长。
.CreatedAt:镜像创建的具体时间。
.Size:镜像硬盘占用空间

docker inspect查看镜像详细信息

格式

docker inspect --format='{{镜像}}'Ubuntu
[root@localhost ~]# docker inspect 5b7e
[
    {
        "Id": "sha256:5b7e2ee8c78d7a7d8410785cb72824a01e52605d2c15b38d0f8da54c8a0ce975",
        "RepoTags": [
            "nginxinc:1",
            "swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginxinc/nginx-unprivileged:1.27-alpine"
        ],
        "RepoDigests": [
            "swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginxinc/nginx-unprivileged@sha256:ce8ea2f4879d11736fe5d12a966a5f03a79cec063b67a6915d278891a155e762"
        ],
        "Parent": "",
        "Comment": "buildkit.dockerfile.v0",
        "Created": "2024-10-14T01:24:20.523389378Z",
        "DockerVersion": "",
        "Author": "",
        "Config": {
            "Hostname": "",
            ...... 

docker history 查看镜像的构建历史

[root@cwf ~]# docker history 5d0c
IMAGE          CREATED        CREATED BY                                       SIZE      COMMENT
5d0cd28768c1   7 months ago   RUN /bin/sh -c set -x     && apkArch="$(cat …   35.6MB    buildkit.dockerfile.v0
<missing>      7 months ago   RUN /bin/sh -c set -x     && apkArch="$(cat …   30.7MB    buildkit.dockerfile.v0
<missing>      7 months ago   ENV NJS_VERSION=0.8.3                            0B        buildkit.dockerfile.v0
<missing>      7 months ago   CMD ["nginx" "-g" "daemon off;"]                 0B        buildkit.dockerfile.v0
<missing>      7 months ago   STOPSIGNAL SIGQUIT                               0B        buildkit.dockerfile.v0
<missing>      7 months ago   EXPOSE map[80/tcp:{}]                            0B        buildkit.dockerfile.v0
<missing>      7 months ago   ENTRYPOINT ["/docker-entrypoint.sh"]             0B        buildkit.dockerfile.v0
<missing>      7 months ago   COPY 30-tune-worker-processes.sh /docker-ent…   4.62kB    buildkit.dockerfile.v0
<missing>      7 months ago   COPY 20-envsubst-on-templates.sh /docker-ent…   3.02kB    buildkit.dockerfile.v0
<missing>      7 months ago   COPY 15-local-resolvers.envsh /docker-entryp…   336B      buildkit.dockerfile.v0
<missing>      7 months ago   COPY 10-listen-on-ipv6-by-default.sh /docker…   2.12kB    buildkit.dockerfile.v0
<missing>      7 months ago   COPY docker-entrypoint.sh / # buildkit           1.62kB    buildkit.dockerfile.v0
<missing>      7 months ago   RUN /bin/sh -c set -x     && addgroup -g 101…   4.56MB    buildkit.dockerfile.v0
<missing>      7 months ago   ENV PKG_RELEASE=1                                0B        buildkit.dockerfile.v0
<missing>      7 months ago   ENV NGINX_VERSION=1.25.4                         0B        buildkit.dockerfile.v0
<missing>      7 months ago   LABEL maintainer=NGINX Docker Maintainers <d…   0B        buildkit.dockerfile.v0
<missing>      8 months ago   /bin/sh -c #(nop)  CMD ["/bin/sh"]               0B        
<missing>      8 months ago   /bin/sh -c #(nop) ADD file:8729f9c0258836b64…   7.34MB    
[root@cwf ~]# 

docker save 将镜像导出到归档文件

[root@cwf ~]# docker save --output hello.tar 5d0c
[root@cwf ~]# docker images 
REPOSITORY                                                                         TAG                        IMAGE ID       CREATED        SIZE
swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.elastic.co/logstash/logstash-oss   8.14.0                     a901f80573eb   3 months ago   796MB
hellov2                                                                            1.0                        5d0cd28768c1   7 months ago   78.1MB
swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx                           mainline-alpine3.18-perl   5d0cd28768c1   7 months ago   78.1MB

docker load 从归档文件加载镜像

[root@cwf ~]# docker load --input hello.tar
Loaded image ID: sha256:5d0cd28768c128082724c83e84bfd410e706170ab47f717b353fab8f590049d7
[root@cwf ~]# 

docker rmi 删除指定的镜像

方法一: docker rmi  镜像ID
方法二: docker rmi 镜像名+TAG
[root@localhost ~]# docker rmi cb8f
Untagged: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx:alpine3.20
Untagged: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx@sha256:76684c43f32804f2601310a067fd5039f85bdf76bb23a477c2a7440f12b883fd
Deleted: sha256:cb8f91112b6b50ead202f48bbf81cec4b34c254417254efd94c803f7dd718045
Deleted: sha256:09f99be15f4ff5db64a85472139db4395c3c14e00c7a90f37499237625556ed4
Deleted: sha256:a3a02df44147c897aef503f952dfa230308fbb8a9bbb5ca28fac36b7b866d6d6
Deleted: sha256:1f47bf4b72792d8c5ea114da41dba55e908ad3b920e8076bec908c771b81d4b4
Deleted: sha256:415c1787dcb7fd187fa40535785c2b3d14d2920ea736ec2a745e1860e92b312a
Deleted: sha256:d0a43343a6d59e04b17a9cc72934e435f6609689259eb4e4adf5658de3eaf8e0
Deleted: sha256:79d58bb4d8ae0b5b8c8cd790f4a8ae29facd883297f357932d3a5266b4f4e30d
Deleted: sha256:adffcb7a535b6915444890e65729bc15929c8fd060c7b4641c57fff05c7f5999
[root@localhost ~]# docker images
REPOSITORY                                                                       TAG           IMAGE ID       CREATED        SIZE
nginxinc                                                                         1             5b7e2ee8c78d   2 months ago   47MB
swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginxinc/nginx-unprivileged   1.27-alpine   5b7e2ee8c78d   2 months ago   47MB
nginx                                                                            2             cb8f91112b6b   2 months ago   47MB
swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx                         alpine3.20    cb8f91112b6b   2 months ago   47MB
[root@localhost ~]# docker rmi nginxinc:1
Untagged: nginxinc:1
[root@localhost ~]# docker rmi nginx:2
Untagged: nginx:2
[root@localhost ~]# docker images
REPOSITORY                                                                       TAG           IMAGE ID       CREATED        SIZE
swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginxinc/nginx-unprivileged   1.27-alpine   5b7e2ee8c78d   2 months ago   47MB
swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx                         alpine3.20    cb8f91112b6b   2 months ago   47MB

docker run 运行镜像

-d   后台运行容器镜像
-it  标准化输出容器id
[root@localhost ~]# docker run -d cb8f
1f65b39480b34915dfaf070c6a6f1181d77011aa07ad99c7f1fa1e8a5224e9fa
[root@localhost ~]# docker run -d -it cb8f
a6a9df8d27ede07393564b8cc9be6a0275977f4f81ed705974cbce0f4e4521e4

docker ps 查看正在运行的容器

-a 所有容器
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND                   CREATED          STATUS          PORTS      NAMES
a6a9df8d27ed   cb8f      "/docker-entrypoint.…"   2 minutes ago    Up 2 minutes    80/tcp     awesome_jones
1f65b39480b3   cb8f      "/docker-entrypoint.…"   4 minutes ago    Up 4 minutes    80/tcp     focused_chatterjee
4a75dbaed8a1   5b7e      "/docker-entrypoint.…"   10 minutes ago   Up 10 minutes   8080/tcp   hungry_lovelace

docker attach 连接正在运行的容器

[root@localhost ~]# docker attach a6a9
2024/12/23 08:12:39 [notice] 1#1: signal 28 (SIGWINCH) received
2024/12/23 08:12:39 [notice] 31#31: signal 28 (SIGWINCH) received
2024/12/23 08:12:39 [notice] 1#1: signal 28 (SIGWINCH) received
2024/12/23 08:12:39 [notice] 31#31: signal 28 (SIGWINCH) received
2024/12/23 08:12:39 [notice] 30#30: signal 28 (SIGWINCH) received
ctrl + c 退出容器

docker container prune 清理没有运行的容器

[root@localhost ~]# docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:
a6a9df8d27ede07393564b8cc9be6a0275977f4f81ed705974cbce0f4e4521e4
1f65b39480b34915dfaf070c6a6f1181d77011aa07ad99c7f1fa1e8a5224e9fa

Total reclaimed space: 2.186kB
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND                   CREATED          STATUS          PORTS      NAMES
4a75dbaed8a1   5b7e      "/docker-entrypoint.…"   16 minutes ago   Up 16 minutes   8080/tcp   hungry_lovelace

docker tag 修改镜像名称和标签

[root@localhost ~]# docker tag swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx:alpine3.20 nginx:2
[root@localhost ~]# docker images
REPOSITORY                                                                       TAG           IMAGE ID       CREATED        SIZE
nginxinc                                                                         1             5b7e2ee8c78d   2 months ago   47MB
swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginxinc/nginx-unprivileged   1.27-alpine   5b7e2ee8c78d   2 months ago   47MB
nginx                                                                            2             cb8f91112b6b   2 months ago   47MB
swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx                         alpine3.20    cb8f91112b6b   2 months ago   47MB
[root@localhost ~]# 

标签:ago,nginx,months,基础,命令,镜像,docker,root
From: https://blog.csdn.net/2403_87303550/article/details/144734146

相关文章

  • java基础3
    异常Java异常类层次结构图概览:Exception和Error有什么区别?在Java中,所有的异常都有一个共同的祖先java.lang包中的Throwable类。Throwable类有两个重要的子类:Exception:程序本身可以处理的异常,可以通过catch来进行捕获。Exception又可以分为CheckedExcept......
  • 命令模式
    命令(Command)模式属于行为型模式的一种。命令模式把请求或者命令封装成一个对象,从而让我们可以使用不同的请求、队列或日志请求、以及支持可撤销的操作等功能。命令模式的核心思想是将请求发送者与请求接收者解耦,使得发送者不需要知道请求的具体细节。实际应用中的场景,比如GUI......
  • AE2024零基础入门
    【AE教程】从零开始学剪辑(新手入门AE2024实用版)AE2024零基础入门教程!!!https://www.bilibili.com/video/BV1iH4y1E7Vy 3 6【AE2024基础课】课程大钢【AE2024基础课】1.界面布局【AE2024基础课】2.首选项设置【AE2024基础课】3.导入素材【AE2024基础课】4.新建合成·课程知......
  • # 学期(如2024-2025-1) 学号(如:20241402) 《计算机基础与程序设计》第14周学习总结
    学期(如2024-2025-1)学号(如:20241402)《计算机基础与程序设计》第14周学习总结作业信息这个作业属于哪个课程<班级的链接>(如2024-2025-1-计算机基础与程序设计)这个作业要求在哪里<作业要求的链接>(如2024-2025-1计算机基础与程序设计第一周作业)这个作业的目标<写上......
  • 打印三角形金字塔 、debug、java的方法、命令行传参、可变参数20241225
    打印三角形金字塔debug20241225packagecom.pangHuHuStudyJava.struct;publicclassPrint_Tran{publicstaticvoidmain(String[]args){for(intj=0;j<5;j++){for(intr=5;r>j;r--){System.out.print(&#......
  • pygame基础功能总结
    1.导入Pygame模块(1) 模块并初始化① Importpygame② Pygame.init()(2) 创建窗体① Window_size=(800,600) 长宽② Screen=pygame.disply.set_mode(Window_size)③ pygame.disply.set_caption(“MyFirstPygameWindow”) 设置窗体标题(3) 主循环① Ru......
  • 零基础微信小程序开发——网络数据请求(保姆级教程+超详细)
    ......
  • GCC安装入门教程(非常详细)从零基础入门到精通,看完这一篇就够了
    1.下载GCC安装包,下载地址如下,选择需要的安装版本:https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/2.解压配置进入解压目录执行:./configure可能会遇到下面的问题:configure:error:BuildingGCCrequiresGMP4.2+,MPFR2.4.0+andMPC0.8.0+.Trythe--with-gmp,--w......
  • Notepad ++ 安装与配置教程(非常详细)从零基础入门到精通,看完这一篇就够了
    Notepad++获取与安装——————————Notepad++是什么在运行中输入notepad会弹出来记事本:所以Notepad++就是增强的记事本!这个跟C与C++的名字是一样滴!Notepad++是开源软件GPL许可证可以免费使用自带中文支持很多计算机编程......
  • RabbitMq的运用(1)—— 基础使用方法介绍
    目录1.RabbitMQ-异步世界的同步器1.1.同步调用1.2.异步调用2.RabbitMq安装1.1windows安装1.2docker安装3.网页端操作3.1登录 3.2队列3.3交换机3.3.1绑定交换机和队列的关系3.3.2发送消息到队列3.3.3在队列中查看信息 3.4更换用户3.4.1新增账号3.4.2创建虚拟......