docker入门(四)—— docker常用命令详解

docker 常用命令

基本命令

# 查看 docker 版本
docker version
# 查看一些 docker 的详细信息
docker info 

帮助命令(–help),linux必须要会看帮助文档

docker --help
[root@iZbp15293q8kgzhur7n6kvZ /]# docker --help

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Common Commands:
  run         Create and run a new container from an image
  exec        Execute a command in a running container
  ps          List containers
  build       Build an image from a Dockerfile
  pull        Download an image from a registry
  push        Upload an image to a registry
  images      List images
  login       Log in to a registry
  logout      Log out from a registry
  search      Search Docker Hub for images
  version     Show the Docker version information
  info        Display system-wide information

Management Commands:
  builder     Manage builds
  buildx*     Docker Buildx (Docker Inc., v0.13.0)
  compose*    Docker Compose (Docker Inc., v2.24.7)
  container   Manage containers
  context     Manage contexts
  image       Manage images
  manifest    Manage Docker image manifests and manifest lists
  network     Manage networks
  plugin      Manage plugins
  system      Manage Docker
  trust       Manage trust on Docker images
  volume      Manage volumes

Swarm Commands:
  swarm       Manage Swarm

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  import      Import the contents from a tarball to create a filesystem image
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  wait        Block until one or more containers stop, then print their exit codes

Global Options:
      --config string      Location of client config files (default "/root/.docker")
  -c, --context string     Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default
                           context set with "docker context use")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket to connect to
  -l, --log-level string   Set the logging level ("debug", "info", "warn", "error", "fatal") (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default "/root/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default "/root/.docker/cert.pem")
      --tlskey string      Path to TLS key file (default "/root/.docker/key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit

Run 'docker COMMAND --help' for more information on a command.

For more help on how to use Docker, head to https://docs.docker.com/go/guides/

docker COMMAND --help可以继续查看其它命令的帮助文档

镜像命令

展示所有的镜像

docker images
[root@iZbp15293q8kgzhur7n6kvZ /]# docker images
# REPOSITORY:镜像仓库
# TAG:标签(版本号),latest 代表最新版
# IMAGE ID:镜像ID,是简化后的
# CREATED:创建时间
# SIZE:镜像大小
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    d2c94e258dcb   10 months ago   13.3kB

参数:

  • -a:等价于--all,显示所有的镜像,包括中间层镜像

默认情况下,docker images命令只显示顶层镜像,即那些没有被其他镜像所依赖的镜像。而使用-a参数,会显示所有的镜像,包括中间层镜像。中间层镜像是构建镜像过程中生成的临时镜像,它们可能被其他镜像所依赖。

  • -q:等价于--quiet,只展示镜像的 id

搜索镜像

docker search 镜像名称
[root@iZbp15293q8kgzhur7n6kvZ /]# docker search mysql
# STARS:星数,最多的通常为我们要找的官方镜像
NAME                            DESCRIPTION                                     STARS     OFFICIAL
mysql                           MySQL is a widely used, open-source relation…   14944     [OK]
mariadb                         MariaDB Server is a high performing open sou…   5703      [OK]
phpmyadmin                      phpMyAdmin - A web interface for MySQL and M…   960       [OK]
percona                         Percona Server is a fork of the MySQL relati…   626       [OK]
bitnami/mysql                   Bitnami MySQL Docker Image                      110       
bitnami/mysqld-exporter                                                         6         
cimg/mysql                                                                      3         
ubuntu/mysql                    MySQL open source fast, stable, multi-thread…   61        
rapidfort/mysql                 RapidFort optimized, hardened image for MySQL   25        
rapidfort/mysql8-ib             RapidFort optimized, hardened image for MySQ…   9         
google/mysql                    MySQL server for Google Compute Engine          25        
elestio/mysql                   Mysql, verified and packaged by Elestio         0         
rapidfort/mysql-official        RapidFort optimized, hardened image for MySQ…   9         
bitnamicharts/mysql                                                             0         
hashicorp/mysql-portworx-demo                                                   0         
databack/mysql-backup           Back up mysql databases to... anywhere!         111       
linuxserver/mysql               A Mysql container, brought to you by LinuxSe…   41        
mirantis/mysql                                                                  0         
docksal/mysql                   MySQL service images for Docksal - https://d…   0         
linuxserver/mysql-workbench                                                     55        
vitess/mysqlctld                vitess/mysqlctld                                1         
eclipse/mysql                   Mysql 5.7, curl, rsync                          1         
drupalci/mysql-5.5              https://www.drupal.org/project/drupalci         3         
drupalci/mysql-5.7              https://www.drupal.org/project/drupalci         0         
datajoint/mysql                 MySQL image pre-configured to work smoothly …   2         

参数:

  • -f:等价于--filter,根据条件搜索想要的镜像
# 过滤出星数不小于500的镜像
docker search mysql -f=STARS=500
[root@iZbp15293q8kgzhur7n6kvZ /]# docker search mysql -f=STARS=500
NAME         DESCRIPTION                                     STARS     OFFICIAL
mysql        MySQL is a widely used, open-source relation…   14944     [OK]
mariadb      MariaDB Server is a high performing open sou…   5703      [OK]
phpmyadmin   phpMyAdmin - A web interface for MySQL and M…   960       [OK]
percona      Percona Server is a fork of the MySQL relati…   626       [OK]

拉取镜像

docker pull 镜像名称:版本号
# 如果不加版本号,则拉取最新版本的镜像
[root@iZbp15293q8kgzhur7n6kvZ /]# docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
72a69066d2fe: Pull complete 
93619dbc5b36: Pull complete 
99da31dd6142: Pull complete 
626033c43d70: Pull complete 
37d5d7efb64e: Pull complete 
ac563158d721: Pull complete 
d2ba16033dad: Pull complete 
688ba7d5c01a: Pull complete 
00e060b6d11d: Pull complete 
1c04857f594f: Pull complete 
4d7cfa90e6ea: Pull complete 
e0431212d27d: Pull complete 
# 签名校验id,主要是保证不会被掉包
Digest: sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest

# 下载指定版本
[root@iZbp15293q8kgzhur7n6kvZ /]# docker pull mysql:5.7
5.7: Pulling from library/mysql
72a69066d2fe: Already exists 
93619dbc5b36: Already exists 
99da31dd6142: Already exists 
626033c43d70: Already exists 
37d5d7efb64e: Already exists 
ac563158d721: Already exists 
d2ba16033dad: Already exists 
0ceb82207cd7: Pull complete 
37f2405cae96: Pull complete 
e2482e017e53: Pull complete 
70deed891d42: Pull complete 
Digest: sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7

删除镜像

docker rmi 镜像名称或镜像ID
[root@iZbp15293q8kgzhur7n6kvZ /]# docker rmi hello-world
Error response from daemon: conflict: unable to remove repository reference "hello-world" (must force) - container 578ad7d53c37 is using its referenced image d2c94e258dcb

这里删除失败是因为 hello-world 镜像有容器正在运行,如果要删除只能强制删除

参数:

  • -f:等价于--force,强制删除镜像,即使有容器正在运行
# 强制删除
[root@iZbp15293q8kgzhur7n6kvZ /]# docker rmi -f hello-world
Untagged: hello-world:latest
Untagged: hello-world@sha256:6352af1ab4ba4b138648f8ee88e63331aae519946d3b67dae50c313c6fc8200f
Deleted: sha256:d2c94e258dcb3c5ac2798d32e1249e42ef01cba4841c2234249495f87264ac5a
# 根据镜像ID删除镜像
[root@iZbp15293q8kgzhur7n6kvZ /]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
mysql        5.7       c20987f18b13   2 years ago   448MB
mysql        latest    3218b38490ce   2 years ago   516MB
[root@iZbp15293q8kgzhur7n6kvZ /]# docker rmi -f 3218b38490ce
Untagged: mysql:latest
Untagged: mysql@sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709
Deleted: sha256:3218b38490cec8d31976a40b92e09d61377359eab878db49f025e5d464367f3b
Deleted: sha256:aa81ca46575069829fe1b3c654d9e8feb43b4373932159fe2cad1ac13524a2f5
Deleted: sha256:0558823b9fbe967ea6d7174999be3cc9250b3423036370dc1a6888168cbd224d
Deleted: sha256:a46013db1d31231a0e1bac7eeda5ad4786dea0b1773927b45f92ea352a6d7ff9
Deleted: sha256:af161a47bb22852e9e3caf39f1dcd590b64bb8fae54315f9c2e7dc35b025e4e3
Deleted: sha256:feff1495e6982a7e91edc59b96ea74fd80e03674d92c7ec8a502b417268822ff

这里镜像ID不一定要是完整的,只要有唯一的一个镜像ID开头满足你输入的ID即可

# 只输入开头的c20即可删除
[root@iZbp15293q8kgzhur7n6kvZ /]# docker rmi -f c20
Untagged: mysql:5.7
Untagged: mysql@sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94
Deleted: sha256:c20987f18b130f9d144c9828df630417e2a9523148930dc3963e9d0dab302a76
Deleted: sha256:6567396b065ee734fb2dbb80c8923324a778426dfd01969f091f1ab2d52c7989
Deleted: sha256:0910f12649d514b471f1583a16f672ab67e3d29d9833a15dc2df50dd5536e40f
Deleted: sha256:6682af2fb40555c448b84711c7302d0f86fc716bbe9c7dc7dbd739ef9d757150
Deleted: sha256:5c062c3ac20f576d24454e74781511a5f96739f289edaadf2de934d06e910b92
Deleted: sha256:8805862fcb6ef9deb32d4218e9e6377f35fb351a8be7abafdf1da358b2b287ba
Deleted: sha256:872d2f24c4c64a6795e86958fde075a273c35c82815f0a5025cce41edfef50c7
Deleted: sha256:6fdb3143b79e1be7181d32748dd9d4a845056dfe16ee4c827410e0edef5ad3da
Deleted: sha256:b0527c827c82a8f8f37f706fcb86c420819bb7d707a8de7b664b9ca491c96838
Deleted: sha256:75147f61f29796d6528486d8b1f9fb5d122709ea35620f8ffcea0e0ad2ab0cd0
Deleted: sha256:2938c71ddf01643685879bf182b626f0a53b1356138ef73c40496182e84548aa
Deleted: sha256:ad6b69b549193f81b039a1d478bc896f6e460c77c1849a4374ab95f9a3d2cea2

删除所有镜像,慎用

重新拉取几个镜像进行测试

删除命令如下:

docker rmi -f $(docker images -aq)
[root@iZbp15293q8kgzhur7n6kvZ /]# docker rmi -f $(docker images -aq)
Untagged: hello-world:latest
Untagged: hello-world@sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
Deleted: sha256:e07ee1baac5fae6a26f30cabfe54a36d3402f96afda318fe0a96cec4ca393359

容器命令

有镜像才能创建容器,我们这里使用 centos 的镜像来测试

根据镜像创建并运行一个容器

docker run 镜像名称
[root@iZbp15293q8kgzhur7n6kvZ /]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
a1d0c7532777: Pull complete 
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest
[root@iZbp15293q8kgzhur7n6kvZ /]# docker run centos
# docker run 执行时自带了 docker pull命令

参数:

  • --name:为容器指定一个名称,不指定则随机一个名字
  • -d:等价于--detach,后台启动容器并打印容器id
  • -i:等价于--interactive,让容器用交互的方式启动
  • -t:等价于--tty,给容器分配一个伪终端,例如/bin/bash
  • -p:等价于--publish,指定端口映射(主机访问的端口:容器端口)
  • -P:大写P,等价于--publish-all,将所有公开的端口发布到随机端口

用交互的方式启动容器,并进入容器内部

docker run -it 镜像名称
[root@iZbp15293q8kgzhur7n6kvZ /]# docker run -it centos
[root@c98e20511eb4 /]# ls
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

退出容器

# 命令,退出后容器停止运行
exit
# 快捷键,退出后容器不会停止
Ctrl + P + Q

查看正在运行中的容器

docker ps
[root@iZbp15293q8kgzhur7n6kvZ /]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED       STATUS       PORTS     NAMES
c98e20511eb4   centos    "/bin/bash"   2 hours ago   Up 2 hours             vibrant_rosalind

参数:

  • -a:等价于--all,显示所有容器,包括已经停止的
  • -q:等价于--quiet,只展示容器ID

容器的启动、重启、停止命令

# 启动一个已经停止的容器
docker start 容器名或容器ID
# 重启一个容器,包括已经停止的容器
docker restart 容器名或容器ID
# 停止一个容器
docker stop 容器名或容器ID
# 强制停止一个容器
docker kill 容器名或容器ID

docker stopdocker kill区别:

docker stop命令会向容器发送一个优雅的停止信号(SIGTERM),让容器有机会进行清理和停止。容器将会接收到该信号并尝试优雅地停止运行中的进程。如果容器在一定时间内没有停止,docker 将会发送一个强制停止信号(SIGKILL)来强制终止容器。这个命令给容器一个正常停止的机会,并且容器可以执行一些清理操作,如保存数据、关闭连接等。

docker kill命令会立即向容器发送一个强制终止信号(SIGKILL),不给容器进行任何清理操作的机会。容器将会立即停止,正在运行的进程将会被强制中断。这个命令是一种强制终止容器的方式,适用于需要立即停止容器的情况。

删除容器

docker rm 容器ID或容器名
[root@iZbp15293q8kgzhur7n6kvZ /]# docker ps -a
CONTAINER ID   IMAGE          COMMAND       CREATED          STATUS                      PORTS     NAMES
7d1b6cececcc   centos         "/bin/bash"   11 minutes ago   Up 11 minutes                         happy_ardinghelli
962ead7ba991   centos         "/bin/bash"   11 minutes ago   Up 11 minutes                         nifty_lovelace
c98e20511eb4   centos         "/bin/bash"   2 hours ago      Up 2 hours                            vibrant_rosalind
d6afbc8233e8   centos         "/bin/bash"   3 hours ago      Exited (0) 3 hours ago                admiring_galois
ba50251e5f7e   centos         "/bin/bash"   3 hours ago      Exited (0) 3 hours ago                nervous_euler
578ad7d53c37   d2c94e258dcb   "/hello"      5 hours ago      Exited (0) 12 minutes ago             gallant_bhaskara
[root@iZbp15293q8kgzhur7n6kvZ /]# docker rm 578a
578a

参数:

  • -f:等价于--force,强制删除容器
# 删除所有容器,包括正在运行和已经停止的,慎用
docker rm -f $(docker ps -aq)
[root@iZbp15293q8kgzhur7n6kvZ /]# docker rm -f $(docker ps -aq)
7d1b6cececcc
962ead7ba991
c98e20511eb4
d6afbc8233e8
ba50251e5f7e
[root@iZbp15293q8kgzhur7n6kvZ /]# docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

以后台方式启动容器 -d

docker run -d centos
[root@iZbp15293q8kgzhur7n6kvZ /]# docker run -d centos
de7eb928d553c5df52f94e27acf604745fa15eb24c40fee60e4059e2bb60b5dd
[root@iZbp15293q8kgzhur7n6kvZ /]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

以后台方式启动容器,查看正在运行时的容器发现没有刚刚启动的容器,这是因为这个镜像 centos 启动的容器里并没有前台进程,所以刚启动一下子就停止了,如果想查询到这个容器,需要加上-a参数

[root@iZbp15293q8kgzhur7n6kvZ /]# docker ps -a
CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS                     PORTS     NAMES
de7eb928d553   centos    "/bin/bash"   2 minutes ago   Exited (0) 2 minutes ago             happy_ride

可以使用-it参数以交互方式启动 centos,这样就有了一个前台进程,容器就不会停止了

[root@iZbp15293q8kgzhur7n6kvZ /]# docker run -itd centos 
b82d98613fd44437b1aa4a1bbff63075604a547ce878e0df9ff76ee13d1b56aa
[root@iZbp15293q8kgzhur7n6kvZ /]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS         PORTS     NAMES
b82d98613fd4   centos    "/bin/bash"   2 seconds ago   Up 2 seconds             beautiful_ramanujan

查看日志

docker logs 容器名或容器id

参数:

  • -t:等价于--timestamps,打印时间戳
  • -f:等价于--follow,打印最新日志并继续输出
  • -n:等价于--tail,从日志末尾输出的行数

这里我们启动一个可以输出日志的容器

# shell 脚本(一个死循环,每隔1s,输出akuya)
docker run -d centos /bin/sh -c "while true;do echo akuya;sleep 1;done"
[root@iZbp15293q8kgzhur7n6kvZ /]# docker run -d centos /bin/sh -c "while true;do echo akuya;sleep 1;done"
5cbf1cd1a21bee0de30fdf53f2bbfc0b690b90b06ce0cd90d4a3e0962de32eab
[root@iZbp15293q8kgzhur7n6kvZ /]# docker ps 
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS     NAMES
5cbf1cd1a21b   centos    "/bin/sh -c 'while t…"   4 seconds ago   Up 4 seconds             romantic_villani
b82d98613fd4   centos    "/bin/bash"              5 minutes ago   Up 5 minutes             beautiful_ramanujan
# 先打印最新5行日志,然后继续输出新的日志,使用快捷键 ctrl+c 停止
[root@iZbp15293q8kgzhur7n6kvZ /]# docker logs -ft -n 5 5cbf1cd1a21b
2024-03-19T13:15:50.993510891Z akuya
2024-03-19T13:15:51.995897632Z akuya
2024-03-19T13:15:52.998156257Z akuya
2024-03-19T13:15:54.000528678Z akuya
2024-03-19T13:15:55.002960756Z akuya
2024-03-19T13:15:56.005416926Z akuya
2024-03-19T13:15:57.007909978Z akuya
2024-03-19T13:15:58.010417478Z akuya

查看容器相关的进程(top)

docker top 容器名或容器id
[root@iZbp15293q8kgzhur7n6kvZ /]# docker top 5cbf1cd1a21b
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                15397               15376               0                   21:11               ?                   00:00:00            /bin/sh -c while true;do echo akuya;sleep 1;done
root                15975               15397               0                   21:20               ?                   00:00:00            /usr/bin/coreutils --coreutils-prog-shebang=sleep /usr/bin/sleep 1

查看容器的元数据(inspect)

docker inspect 容器名或容器id
[root@iZbp15293q8kgzhur7n6kvZ /]# docker inspect 5cbf1cd1a21b
[
    {
        "Id": "5cbf1cd1a21bee0de30fdf53f2bbfc0b690b90b06ce0cd90d4a3e0962de32eab",
        "Created": "2024-03-19T13:11:32.102190519Z",
        "Path": "/bin/sh",
        ......
]

进入一个正在进行的容器

docker exec -it 容器名或容器id shell脚本程序(例如/bin/sh或/bin/bash,如果不加默认进入正在执行的终端)
docker attach 容器名或容器id
# 不加/bin/bash则会进入到正在运行的/bin/sh中,也就是那个死循环的程序
[root@iZbp15293q8kgzhur7n6kvZ /]# docker exec -it 5cbf1cd1a21b /bin/bash
[root@5cbf1cd1a21b /]# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 13:11 ?        00:00:00 /bin/sh -c while true;do echo akuya;sleep 1;done
root      1138     0  0 13:30 pts/0    00:00:00 /bin/bash
root      1161     1  0 13:30 ?        00:00:00 /usr/bin/coreutils --coreutils-prog-shebang=sleep /usr/bin/sleep 1
root      1162  1138  0 13:30 pts/0    00:00:00 ps -ef
# 进入到正在执行的程序中,也就是死循环,需要重新启动一下服务器
[root@iZbp15293q8kgzhur7n6kvZ /]# docker attach 5cbf1cd1a21b
akuya
akuya
akuya
akuya
akuya

区别:

  • execdocker exec命令用于在正在运行的容器中执行一个新的命令。它会创建一个新的进程,并在容器中执行指定的命令。该命令会在容器的新进程中执行,不会影响容器原有的主进程。使用docker exec可以在容器内部执行命令、进入容器的交互式终端,并且可以在后台运行的容器中执行任务。
  • attachdocker attach命令用于连接到正在运行的容器的标准输入(stdin)、输出(stdout)和错误输出(stderr)。该命令会将你的终端会话附加到容器的主进程上,并将容器的输出直接显示在你的终端上。使用docker attach可以实时查看和参与到容器内部正在运行的进程中,但是当你退出终端会话时,容器将会停止运行。

拷贝容器内的文件到主机上

docker cp 容器名或容器id:容器内文件地址 主机地址
[root@iZbp15293q8kgzhur7n6kvZ ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS     NAMES
5cbf1cd1a21b   centos    "/bin/sh -c 'while t…"   23 minutes ago   Up 23 minutes             romantic_villani
b82d98613fd4   centos    "/bin/bash"              28 minutes ago   Up 28 minutes             beautiful_ramanujan
[root@iZbp15293q8kgzhur7n6kvZ ~]# docker attach b82d98613fd4
[root@b82d98613fd4 /]# ls
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@b82d98613fd4 /]# cd /home
[root@b82d98613fd4 home]# touch a.txt
# 快捷键退出容器
[root@b82d98613fd4 home]# read escape sequence
[root@iZbp15293q8kgzhur7n6kvZ ~]# docker cp b82d98613fd4:/home/a.txt /home
Successfully copied 1.54kB to /home
[root@iZbp15293q8kgzhur7n6kvZ ~]# cd /home
[root@iZbp15293q8kgzhur7n6kvZ home]# ll
total 0
-rw-r--r-- 1 root root 0 Mar 19 21:40 a.txt

常用命令总结

在这里插入图片描述

常用命令:

docker --help 

attach    Attach to a running container                 # 当前 shell 下 attach 连接指定运行镜像
build     Build an image from a Dockerfile              # 通过 Dockerfile 定制镜像
commit    Create a new image from a container changes   # 提交当前容器为新的镜像
cp        Copy files/folders from the containers filesystem to the host path   #从容器中拷贝指定文件或者目录到宿主机中
create    Create a new container                        # 创建一个新的容器,同 run,但不启动容器
diff      Inspect changes on a container's filesystem   # 查看 docker 容器变化
events    Get real time events from the server          # 从 docker 服务获取容器实时事件
exec      Run a command in an existing container        # 在已存在的容器上运行命令
export    Stream the contents of a container as a tar archive   # 导出容器的内容流作为一个 tar 归档文件[对应 import ]
history   Show the history of an image                  # 展示一个镜像形成历史
images    List images                                   # 列出系统当前镜像
import    Create a new filesystem image from the contents of a tarball # 从tar包中的内容创建一个新的文件系统映像[对应export]
info      Display system-wide information               # 显示系统相关信息
inspect   Return low-level information on a container   # 查看容器详细信息
kill      Kill a running container                      # kill 指定 docker 容器
load      Load an image from a tar archive              # 从一个 tar 包中加载一个镜像[对应 save]
login     Register or Login to the docker registry server    # 注册或者登陆一个 docker 源服务器
logout    Log out from a Docker registry server          # 从当前 Docker registry 退出
logs      Fetch the logs of a container                 # 输出当前容器日志信息
port      Lookup the public-facing port which is NAT-ed to PRIVATE_PORT    # 查看映射端口对应的容器内部源端口
pause     Pause all processes within a container        # 暂停容器
ps        List containers                               # 列出容器列表
pull      Pull an image or a repository from the docker registry server   # 从docker镜像源服务器拉取指定镜像或者库镜像
push      Push an image or a repository to the docker registry server    # 推送指定镜像或者库镜像至docker源服务器
restart   Restart a running container                   # 重启运行的容器
rm        Remove one or more containers                 # 移除一个或者多个容器
rmi       Remove one or more images             # 移除一个或多个镜像[无容器使用该镜像才可删除,否则需删除相关容器才可继续或 -f 强制删除]
run       Run a command in a new container              # 创建一个新的容器并运行一个命令
save      Save an image to a tar archive                # 保存一个镜像为一个 tar 包[对应 load]
search    Search for an image on the Docker Hub         # 在 docker hub 中搜索镜像
start     Start a stopped containers                    # 启动容器
stop      Stop a running containers                     # 停止容器
tag       Tag an image into a repository                # 给源中镜像打标签
top       Lookup the running processes of a container   # 查看容器中运行的进程信息
unpause   Unpause a paused container                    # 取消暂停容器
version   Show the docker version information           # 查看 docker 版本号
wait      Block until a container stops, then print its exit code   # 截取容器停止时的退出状态值

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/469680.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Grok ai——很牛叉的ai工具Grok-1大模型

Grok Grok 是一款仿照《银河系漫游指南》(Hitchhikers Guide to the Galaxy)设计的人工智能。它可以回答几乎任何问题,更难的是,它甚至可以建议你问什么问题! Grok 是一个仿照《银河系漫游指南》设计的人工智能&#x…

数据结构:详解【顺序表】的实现

1. 顺序表的定义 顺序表是用一段物理地址连续的存储单元依次存储数据元素的线性结构,一般情况下采用数组存储。动态顺序表与数组的本质区别是——根据需要动态的开辟空间大小。 2. 顺序表的功能 动态顺序表的功能一般有如下几个: 初始化顺序表打印顺序…

计算机组成原理-3-系统总线

3. 系统总线 文章目录 3. 系统总线3.1 总线的基本概念3.2 总线的分类3.3 总线特性及性能指标3.4 总线结构3.5 总线控制3.5.1 总线判优控制3.5.2 总线通信控制 本笔记参考哈工大刘宏伟老师的MOOC《计算机组成原理(上)_哈尔滨工业大学》、《计算机组成原理…

spring suite搭建springboot操作

一、前言 有时候久了没开新项目了,重新开发一个新项目,搭建springboot的过程都有点淡忘了,所有温故知新。 二、搭建步骤 从0开始搭建springboot 1.创建work空间。步骤FileNewJava Working Set。 2.选择Java Working Set。 3.自…

微信小程序接口请求出错:request:fail url not in domain list:xxxxx

一、微信小程序后台和开发者工具配的不一样导致了这个错误 先说结论: 开发者工具配置了https://www.xxx.cn/prod-api/ 微信后台配置了 https://www.xxx.cn 一、最开始 开发者工具配置了https://www.xxx.cn:7500 微信后台配置了 https://www.xxx.cn 报错:reques…

OPTEE v3.20.0 FVP环境搭建

目录 一、前提条件 二、下载fvp代码 三、下载工具链 四、下载Foundation_Platform FVP平台 五、编译及运行 一、前提条件 1、安装如下的依赖工具 sudo apt-get install android-tools-adb android-tools-fastboot autoconf \ automake bc bison build-essential ccache c…

2024精灵传信系统支持电脑PC端+小程序双端源码

2024精灵传信系统支持电脑PC端小程序双端源码 精灵传信支持在线提交发送短信,查看回复短信,在线购买额度,自定义对接易支付,设置违禁词,支持网站小程序双端。 搭建环境: PHP > 73 MySQL>5.6 Nginx…

当两会热词碰上“人工智能+”,你知道哪些企业算是行业弄潮儿吗?

最近正值全国“两会”的召开,一大批新词热词涌现,聚焦了各行各业的发展,也一定程度上代表了未来的主要发展方向。“未来产业”、“人工智能”、“全国一体化算力体系”等热词的出圈充分表明了信息技术行业是一大发展重点,尤其是人…

护航容器安全:私有Registry在镜像审核中的关键角色与实战策略

在容器化技术日益普及的今天,Docker镜像的质量与安全性成为了构建稳定、可靠应用的关键要素。私有Registry作为镜像的集中存储和分发中心,不仅可以提供镜像的统一管理,还能通过集成镜像审核机制,确保进入生产环境的镜像符合安全与…

如何解决MySQL死锁(看懂MySQL锁日志)

有时候系统在生产运行着,会突然爆出 [40001][1213] Deadlock found when trying to get lock; try restarting transaction 这个时候每个人都会很紧张,因为死锁会影响DB性能,严重时甚至拖垮整个系统。在实际的环境中,很多服务会共…

【电路笔记】-达林顿晶体管

达林顿晶体管 文章目录 达林顿晶体管1、概述2、基本达林顿晶体管配置3、示例4、达林顿晶体管应用5、Sziklai 晶体管对6、ULN2003A 达林顿晶体管阵列7、总结两个双极晶体管的达林顿晶体管配置可针对给定基极电流提供更大的电流切换。 1、概述 达林顿晶体管以其发明者 Sidney Da…

文件包含漏洞之包含NGINX日志文件(常用)

条件:知道目标服务器的日志文件存贮路径,并且存在文件包含漏洞 首先对目标服务器发送一次含有木马的请求,目的是让目标服务器日志中生成含有木马的日志记录。因为发送过程中,使用了url编码,我们抓包进行更改成能够执行…

【Python爬虫】详解BeautifulSoup()及其方法

文章目录 🍔准备工作🌹BeautifulSoup()⭐代码实现✨打印标签里面的内容✨快速拿到一个标签里的属性✨打印整个文档🎆获取特定标签的特定内容 🌹查找标签🎈在文档查找标签 find_all🎈正则表达式搜索 &#x…

echarts geo地图加投影两种方法

方法1,geo中加多个地图图形,叠加。缩放时 可能会不一致,需要捕捉georoam事件,使下层的geo随着上层的geo一起缩放拖曳 geo: [{zlevel: 3,//geo显示级别,默认是0 【最顶层图形】map: BJ,//地图名roam: true,scaleLimit: …

虚拟机VMware上 centos7 的网络配置

第一步:权限的切换 由普通用户切换到管理者/超级用户 用户名为:root 密码为:自己安装 linux 时第一次设置的密码 su -root管理者/超级用户的命令提示符是“#”,普通用户的命令提示符是“$”。当看到你的命令提示符为“$”时&…

VScode 设置个性化背景(保姆级教程)

VS Code设置个性化背景的作用主要体现在以下几个方面: 提升编程体验:个性化背景能够让编程环境更符合个人的审美和习惯,使得长时间在VS Code中进行代码编辑时,能够保持愉悦的心情,从而提高编程效率。减少视觉疲劳&…

微隔离是什么,有什么作用

传统的网络安全架构通常是基于较大的安全区域(如子网或虚拟局域网),在这些区域内的设备可以相互通信。然而,这也意味着一旦内部的设备被威胁或遭到入侵,攻击者可能会在整个安全区域内进行横向移动和渗透。 微隔离通过…

GNSS载波相位平滑伪距基本原理

相位平滑技术:削弱伪距欢测值的随机误差影响 差分技术:削弱欢测方程中的系统误差影响 相位平滑伪距原理: GPS接收机除了提供伪距测量外,可同时提供载波相位测量,由于载波相位测量的精度比码相位的测量精度高2个数量…

蓝桥杯嵌入式第十届省赛 真题+代码

led.c文件 #include "led.h"void Led(uint16_t addr,uint16_t enable) {static uint16_t temp 0x0000;static uint16_t temp_old 0xffff;HAL_GPIO_WritePin(GPIOC, GPIO_PIN_All, GPIO_PIN_SET);if(enable)temp | 0x0100 << addr;elsetemp & ~(0x0100 &…

在sql server 2016 always on集群里新增一个数据库节点

本篇博客有对应的word版本&#xff0c;有需要的可以点击这里下载。 一 环境介绍 二 操作步骤 2.1 在新节点上安装sql server软件 略 2.2 在新节点上开启‘故障转移群集功能’ 打开‘服务管理器’&#xff1a; 点击‘添加角色和功能’&#xff1a; 勾选’DNS服务器’&#…
最新文章