Docker基础命令讲解(3)

1.创建并运行一个centos容器。

[root@node ~]# docker run -dit centos:7 /bin/bash
08591b3091ecfb10081efc40f4f066e3eb91413689b5843d7425d60d0b89c4c7

docker run -dit centos:7 /bin/bash


centos:7   7为自己下载的版本

2.对容器进行启动,停止,重启等操作。

[root@node ~]# docker start 08
08
[root@node ~]# docker stop 08
08

[root@node ~]# docker restart 08
08

docker start +容器id
docker stop  +容器id
docker restart +容器id

3.删除容器

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

Remove one or more containers

Options:
  -f, --force     Force the removal of a running container (uses SIGKILL)   强制移除正在运行的容器(使用SIGKILL)  
  -l, --link      Remove the specified link    删除指定的链接

  -v, --volumes   Remove the volumes associated with the container 删除与容器关联的卷 

[root@node ~]# docker rm -f 08
08

docker rm -f 08

08为容器id

4.导入和导出容器

导出成.tar 文件

导入时将.tar 文件导入

docker export -h

Usage:    docker export [OPTIONS] CONTAINER

Export a container's filesystem as a tar archive

Options:
  -o, --output string   Write to a file, instead of STDOUT  写入一个文件内

root@node ~]# docker export -o  centos.tar b5
[root@node ~]# ls
1.txt  1.xt  a.sh  centos.tar  dskajhjd.txt  news_files  news.html

docker export -o centos.tar b5

centos.tar 导出名字

b5  导出模板

docker import

Usage:    docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]

Import the contents from a tarball to create a filesystem image

Options:
  -c, --change list      Apply Dockerfile instruction to the created image 对创建的映像应用Dockerfile指令
  -m, --message string   Set commit message for imported image  为导入的图像设置提交信息

5,查看容器信息

Usage:    docker inspect [OPTIONS] NAME|ID [NAME|ID...]

Return low-level information on Docker objects

Options:
  -f, --format string   Format the output using the given Go template    使用给定的Go模板格式化输出

  -s, --size            Display total file sizes if the type is container  如果类型是容器,则显示总的文件大小  
      --type string     Return JSON for specified type  返回指定类型的JSON

docker inspect 05

[root@node ~]# docker inspect 50
[
    {
        "Id": "5021c24258c0402b6d459830d3264217ff657fc5fd016f84ebc1a6a3ef6ac055",
        "Created": "2022-02-23T06:48:16.167957366Z",
        "Path": "/docker-entrypoint.sh",
        "Args": [
            "nginx",
            "-g",
            "daemon off;"

。。。。。。。

docker inspect 05 | grep Pid 

查看容器Pid

6.查看容器日志

Usage:    docker logs [OPTIONS] CONTAINER

Fetch the logs of a container

Options:
      --details        Show extra details provided to logs   显示提供给日志的额外细节

  -f, --follow         Follow log output       跟踪日志输出
      --since string   Show logs since timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)        显示时间戳(如2013-01-02T13:23:37)或相对时间戳(如42m for 42 minutes)之后的日志  
      --tail string    Number of lines to show from the end of the logs (default "all")从日志末尾显示的行数(默认为“all”) 
  -t, --timestamps     Show timestamps   显示时间戳
      --until string   Show logs before a timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)    在时间戳(如2013-01-02T13:23:37)或相对时间戳(如42m for 42 minutes)之前显示日志  

7. 其他容器管理命令

1)docker pause 用于暂定容器进程,docker unpause恢复容器进程

2)docker port 查看容器与主机映射端口号

[root@node ~]# docker port 50
80/tcp -> 0.0.0.0:80

3)容器重命名

docker rename 旧    新

4)docker stats 容器资源消耗情况动态统计信息,CPU,内存,网络

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  使用Go模板打印漂亮的图像

      --no-stream       Disable streaming stats and only pull the first result  禁用流统计,只拉第一个结果  
      --no-trunc        Do not truncate output  不截断输出

5)查看容器进程信息

docker  ps

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

a'ゞ过去已成回忆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值