Docker基础命令

1 查看Docker是否正常工作

sudo docker info

2 运行Docker容器

sudo docker run --name container_name -i -t ubuntu /bin/bash

在容器中,通过exit命令退出。

3 重启已经停止运行的容器

sudo docker start container_name

4 附着到正在运行的容器

sudo docker attach container_name

5 创建守护式容器

sudo docker run --name container_name -d ubuntu /bin/sh -c "while true;do echo hello world; sleep 1;done"

6 获取守护式容器的日志

sudo docker logs container_name

7 跟踪守护式容器的日志

sudo docker logs -f container_name

8 查看守护式容器的进程

sudo docker top container_name

9 查看docker统计信息

sudo docker stats container_name

10 在容器中运行后台任务

sudo docker exec -d container_name touch /etc/newfile

11 停止守护容器

sudo docker stop container_name

12 自动重启守护容器

sudo docker run --restart=always --name container_name -d ubuntu /bin/sh -c "while true;do echo hello world; sleep 1;done"

sudo docker run --restart=on-failure:5 --name container_name -d ubuntu /bin/sh -c "while true;do echo hello world; sleep 1;done"

13 查看容器

sudo docker inspect container_name

14 删除容器

sudo docker rm container_name

15 删除所有容器

sudo docker rm 'sudo docker ps -a -q'
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值