Docker 常用命令
systemctl restart docker #重启 Docker
docker images #查看镜像文件
REPOSITORY #镜像的仓库源
TAG #镜像的标签
IMAGE ID #镜像的创建时间
docker pull nginx:1.20.0 #拉取版本为 1.20.0 的 nginx 应用
docker run xxx #运行容器
docker ps -a #查看所有容器
docker stop xxx #容器名称或CONTAINER ID
docker rm xxx #删除容器
docker info #查看 Docker 的信息
docker stats xxx #查看xxx容器运行状态,xxx不指定,查看所有容器运行状态(内存、CPU占有用情况)
docker container update --restart=always XXX #当Docker启动后,同步启动 XXX容器
docker stop $(docker ps -q) #停止所有容器
docker rm $(docker ps -aq) #删除所有空口
docker stop $(docker ps -q) & docker rm $(docker ps -aq) #停止并删除所有容器
docker rmi -f $(docker images -qa) #删除所有镜像
容器操作常用命令
docker exec -it xxx /bin/bash # 进入容器
docker logs --since 30m elasticsearch
docker logs --tail=100 -f elasticsearch
docker ps --format "table {{.ID}} {{.Names}} {{.RunningFor}} {{.Status}}"
#将容器中的文件复制到宿主机中
docker cp XXX:/usr/share/elasticsearch/config/elasticsearch.yml /opt/elasticsearch/config/elasticsearch.yml
#数据卷容器,volumes同步
docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 --name mysql02 --volumes-form mysql01
docker ps --format
名称 | 含义 |
---|---|
.ID | 容器ID |
.Image | 镜像ID |
.Command | 执行的命令 |
.CreatedAt | 容器创建时间 |
.RunningFor | 运行时长 |
.Ports | 暴露的端口 |
.Status | 容器状态 |
.Names | 容器名称 |
.Label | 分配给容器的所有标签 |
.Mounts | 容器挂载的卷 |
.Networks | 容器所用的网络名称 |
#1秒种写一次日志
docker run -d centos /bin/sh -c "while true;do echo kuangshen;sleep 1;done"