Dcoker常规命令大全

docker常用命令

1、帮助命令

#查看docker版本
 docker version
#查看docker的详细信息 包括镜像和容器数量
docker info
#帮助命令
docker 命令 --help

帮助文档地址:https://docs.docker.com/engine/reference/

2、镜像命令

[root@localhost ~]# docker  images
REPOSITORY                                                                TAG              IMAGE ID       CREATED         SIZE
135.32.104.186:8021/boco/oss-security-manager                             1.0.0.62         995e9ae6ddba   3 weeks ago     936MB
oss.harbor:8089/znjk_tiangong/oss-security-manager                        1.0.0.62         995e9ae6ddba   3 weeks ago     936MB
#REPOSITORY 镜像仓库源
#TAG 镜像标签
#IMAGE ID  镜像ID
#CREATED 创建时间
#SIZE 镜像大小

#可选项
[root@localhost ~]# docker images --help

Usage:  docker images [OPTIONS] [REPOSITORY[:TAG]]

List images

Options:
  -a, --all             Show all images (default hides intermediate images)
  -q, --quiet           Only show image IDs

#docker search 搜索仓库镜像
[root@localhost ~]# docker search mysql
NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql                             MySQL is a widely used, open-source relation…   11665     [OK]       
mariadb                           MariaDB Server is a high performing open sou…   4444      [OK]       
mysql/mysql-server                Optimized MySQL Server Docker images. Create…   867                  [OK]
#可选项
--filter-STARS=3000 #搜索STARS大于3000的

下载镜像

[root@localhost ~]# docker pull mysql
Using default tag: latest #没有指定tag 下载最新的
latest: Pulling from library/mysql
b380bbd43752: Pull complete #分层下载 docker images的核心 联合文件系统
f23cbf2ecc5d: Pull complete 
30cfc6c29c0a: Pull complete 
b38609286cbe: Pull complete 
8211d9e66cd6: Pull complete 
2313f9eeca4a: Pull complete 
7eb487d00da0: Pull complete 
4d7421c8152e: Pull complete 
77f3d8811a28: Pull complete 
cce755338cba: Pull complete 
69b753046b9f: Pull complete 
b2e64b0ab53c: Pull complete 
Digest: sha256:6d7d4524463fe6e2b893ffc2b89543c81dec7ef82fb2020a1b27606666464d87 #签名
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest #镜像的真实地址 等价于docker pull mysql
#指定版本
docker pull mysql:5.7

docker rmi 删除镜像

#删除指定的容器
[root@localhost ~]# docker rmi -f ecac195d15af
#删除多个
docker rmi -f ecac195d15af 镜像ID 镜像ID
#删除全部
docker rmi -f $(docker images -qa)

3、容器的命令

有了镜像才可以去创建容器

docker pull centos

新建容器并启动

docker run [可选参数] image
#参数说明
#--name="Name"     容器名字
#-d             以后台方式运行 nohup
#-it             使用交互方式运行,进入容器查看内容
#-p                制定容器端口 - 8080:8080
    #-p 主机端口:容器端口
    #-p 容器端口
    #容器端口
#-P                随机指定窗口

#启动并进入容器
[root@localhost ~]# docker run -it centos /bin/bash
#退出命令
[root@69d7c03452eb /]# exit 

查看容器运行命令

#docker ps 命令
#参数
#  空 显示正在运行的容器
#-a   显示所有的容器,包括曾经运行过得容器
#-n=? 显示最近运行的容器
#-q   只显示容器编号
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS                     PORTS     NAMES
69d7c03452eb   centos    "/bin/bash"   2 minutes ago   Exited (0) 7 seconds ago             funny_borg

退出容器

exit  #直接容器停止并退出
Ctrl +P +Q #容器不停止退出

删除容器

docker rm 容器ID                    #删除指定的容器,不能删除运行中的 如果需要删除 加-f
docker rm -f $(docker ps -qa)     #删除所有的容器
docker ps -a-q|xargs docker rm      #删除所有的容器

启动和停止容器

docker start 容器ID         #启动
docker stop 容器ID        #停止
docker restart  容器ID    #重启
docker kill 容器ID         #强制停止当前的容器

4、常见其他命令

后台启动

#命令 docker run -d 镜像名
docker run -d centos
#问题 docker ps 发现centos停止了
#常见的坑 docker容器使用后台运行,就需要要有一个前台的进程,docker发现没有应用就自动停止

查看日志

# -tf
#--tail 10 
docker logs -tf --tail 10 容器ID

查看容器中的进程信息

docker top 容器ID

查看镜像的元数据

docker inspect 容器ID

进入当前正在运行的容器

#通常容器都是使用后台按时运行
#进入容器开启一个新的终端
docker exec -it 容器ID /bin/bash
#正在执行 
#进入当前正在运行的终端
docker attach 容器ID

容器内文件拷贝到外面

docker cp 容器ID:容器内路径  目的主机路径

5、实战练习

安装nginx

安装tomcat

安装es+Kibana

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值