Docker学习记录-docker的基本命令

本文档详细记录了Docker的学习过程,包括Docker的基本命令使用,如镜像、容器的创建、启动、停止和删除。重点介绍了Docker镜像的概念,解释了镜像是如何通过分层加载的UnionFS工作,并通过实例展示了如何部署Nginx和Tomcat。通过练习加深了对Docker镜像和容器的理解。
摘要由CSDN通过智能技术生成

Docker学习记录-01

docker文档地址

Docker overview | Docker Documentation

帮助命令

docker 命令 --help

镜像命令

#显示镜像
[root@VM-12-9-centos ~]# docker images
REPOSITORY        TAG       IMAGE ID       CREATED        SIZE
nginx             latest    7425d3a7c478   4 days ago     142MB
whyour/qinglong   latest    2b6f05a5ef3d   6 months ago   419MB
centos            latest    5d0da3dc9764   8 months ago   231MB
#可选项
Options:
  -a, --all             显示所有镜像
      --digests         更深层次的挖掘
  -q, --quiet           只显示镜像ID
#搜索镜像
[root@VM-12-9-centos ~]# docker search tomcat
#搜索添加过滤
[root@VM-12-9-centos ~]# docker search tomcat --filter=stars=3000
NAME      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
tomcat    Apache Tomcat is an open source implementati…   3319      [OK]       
#下载镜像 比如下载mysql镜像
[root@VM-12-9-centos ~]# docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
c32ce6654453: Pull complete #采用分层下载方式
415d08ee031a: Pull complete 
7a38fec2542f: Pull complete 
352881ee8fe9: Pull complete 
b8e20da291b6: Pull complete 
66c2a8cc1999: Pull complete 
d3a3a8e49878: Pull complete 
e33a48832bec: Pull complete 
410b942b8b28: Pull complete 
d5323c9dd265: Pull complete 
3212737f31c0: Pull complete 
d0032d4b0dc5: Pull complete 
Digest: sha256:a0805d37d4d298bd61e0dfa61f0ddf6f4680b453fa25d7aad420485a62417eab
Status: Downloaded newer image for mysql:latest #默认下载

#指定版本下载
[root@VM-12-9-centos ~]# docker pull mysql:5.7
5.7: Pulling from library/mysql
c32ce6654453: Already exists #分层下载这些模块刚才已经下载不需要在下载
415d08ee031a: Already exists 
7a38fec2542f: Already exists 
352881ee8fe9: Already exists 
b8e20da291b6: Already exists 
66c2a8cc1999: Already exists 
d3a3a8e49878: Already exists 
172aabfba65c: Pull complete 
fea17d0b1d1e: Pull complete 
fff7f5411ca9: Pull complete 
c33d43428e07: Pull complete 
Digest: sha256:16e159331007eccc069822f7b731272043ed572a79a196a05ffa2ea127caaf67
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7

#删除镜像 指定id删除
[root@VM-12-9-centos ~]# docker rmi -f 76152be68449
#删除镜像 全部删除
[root@VM-12-9-centos ~]# docker rmi -f $(docker images -aq)

容器命令

说明:有了镜像才可以创建容器

运行容器&列出容器

docker run [可选参数] images
#参数说明
--name="名字" 容器名字用来区分容器
-d            后台方式运行
-it           交互方式运行,进入容器
-p            指定容器端口 -p 8080:8080
      -p 8080:8080(主机端口:容器端口)最常用
      -p 容器端口
       容器端口

—P             随机端口
#测试 启动centos镜像并进入容器
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

小小徐404

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

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

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

打赏作者

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

抵扣说明:

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

余额充值