k8s

第七章 Docker---容器的命令详解

2018-11-26  本文已影响0人  箫起秦楼

1. Docker容器的特殊规则:

2. 创建容器

[root@centos_7_1]:[~]# docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@centos_7_1]:[~]# docker container run --name a1 -it alpine:3.8
/ #
/ # ls /
bin    dev    etc    home   lib    media  mnt    proc   root   run    sbin   srv    sys    tmp    usr    var
/ #
#-------------------保持当前终端不退出,另开一个终端,查看当前主机有哪些容器-------------------
[root@centos_7_1]:[~]# docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
164b90dacf73        alpine:3.8          "/bin/sh"           About a minute ago   Up About a minute                       a1

上述命令详细说明:

3. 退出容器

/ # ls /
bin    dev    etc    home   lib    media  mnt    proc   root   run    sbin   srv    sys    tmp    usr    var
/ # exit
[root@centos_7_1]:[~]#
#-----------------------------另开一个终端,查看当前有哪些终端-----------------------------
[root@centos_7_1]:[~]# docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@centos_7_1]:[~]# docker container ls -a
CONTAINER ID        IMAGE                 COMMAND              CREATED             STATUS                      PORTS    NAMES
164b90dacf73        alpine:3.8            "/bin/sh"            3 minutes ago       Exited (0) 7 seconds ago

4. 打开已停止的容器

[root@centos_7_1]:[~]# docker container start a1
a1
[root@centos_7_1]:[~]# docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS           NAMES
164b90dacf73        alpine:3.8          "/bin/sh"           26 minutes ago      Up 2 seconds           a1
[root@centos_7_1]:[~]# docker container attach a1
/ #
/ #
#-----------------------------分割线-----------------------------
# 使用快捷键剥离终端
[root@centos_7_1]:[~]#
[root@centos_7_1]:[~]# docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
164b90dacf73        alpine:3.8          "/bin/sh"           15 hours ago        Up 17 seconds                           a1
[root@centos_7_1]:[~]# docker container stop a1
a1
[root@centos_7_1]:[~]#
[root@centos_7_1]:[~]# docker container ls -a
CONTAINER ID        IMAGE                 COMMAND              CREATED             STATUS                          PORTS        NAMES
164b90dacf73        alpine:3.8            "/bin/sh"            15 hours ago        Exited (137) 9 seconds ago        a1

** 上述命令详细说明:**

5. Docker容器命令的所有子命令

[root@centos_7_1]:[~]# docker container --help

Usage:  docker container COMMAND

Manage containers

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
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  inspect     Display detailed information on one or more containers
  kill        Kill one or more running containers
  logs        Fetch the logs of a container
  ls          List containers
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  prune       Remove all stopped containers
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  run         Run a command in a new container
  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
  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

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

6. Docker新版本与老版本命令对比

[root@centos_7_1]:[~]# docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
164b90dacf73        alpine:3.8          "/bin/sh"           16 hours ago        Up 3 seconds                            a1
[root@centos_7_1]:[~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
164b90dacf73        alpine:3.8          "/bin/sh"           16 hours ago        Up 7 seconds                            a1

| :----- | :-----: |
| 第一章 初识Docker | 点击此处 |
| 第二章 安装Docker以及简单配置 | 点击此处 |
| 第三章 Docker容器的生命周期 | 点击此处 |
| 第四章 Docker命令汇总 | 点击此处 |
| 第五章 Docker基础命令详解 | 点击此处 |
| 第六章 Docker---镜像的命令详解 | 点击此处 |
| 第七章 Docker---容器的命令详解 | 点击此处 |
| 第八章 Docker与Alpine不解之缘 | 点击此处 |
|未完待续| |

上一篇 下一篇

猜你喜欢

热点阅读