运维之道 | Docker 容器使用

本文详细介绍了Docker容器的使用,包括Docker客户端操作、容器的启动、后台运行、停止与进入、导出与导入,以及如何运行和管理web应用程序。讲解了如何使用docker run、docker start、docker attach、docker exec等命令,并展示了如何映射端口、查看容器日志、检查进程,以及停止和重启web应用容器。
摘要由CSDN通过智能技术生成

Docker 容器使用

一、Docker 客户端

Docker 客户端非常简单 ,我们可以直接输入 docker 命令来查看到 Docker 客户端的所有命令选项。

[root@localhost ~]#: docker

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

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(s) 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

可以通过命令 docker command --help 更深入的了解指定的 Docker 命令使用方法。

例如我们要查看 docker stats 指令的具体使用方法:

[root@localhost ~]#: docker stats --help

Usage:  docker stats [OPTIONS] [CONTAINER...]

Display a live stream of container(s) resource usage statistics

Options:
  -a, --all             Show all containers (default shows just running)
      --format string   Pretty-print images using a Go template
      --no-stream       Disable streaming stats and only pull the first result
      --no-trunc        Do not truncate output

二、容器使用

1、启动容器
以下命令使用 centos 镜像启动一个容器:

[root@localhost ~]#: docker run -it centos /bin/bash
[root@966229a88406 /]# 

参数说明:

  • -i: 交互式操作。
  • -t: 终端。
  • centos:centos 镜像。
  • /bin/bash:放在镜像名后的是命令,这里我们希望有个交互式 Shell,因此用的是 /bin/bash。

要退出终端,直接输入 exit:

[root@966229a88406 /]# exit
exit
[root@localhost ~]#:

2、启动已停止运行的容器
查看所有的容器命令docker ps -a

[root@localhost ~]#: docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                           PORTS               NAMES
966229a88406        centos              "/bin/bash"              6 minutes ago       Exited (0)                     4 minutes ago                        suspicious_perlman
617a601fb31b        centos              "/bin/sh -c 'while t…"
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值