linux怎么查看本机内存大小
248
2022-10-20
Docker 镜像及容器命令
十年河东,十年河西,莫欺少年穷
学无止境,精益求精
授人以鱼不如授人以渔,先列出官方命令文档
docker命令文档地址:镜像基本命令大致分为,查看镜像,搜索镜像,下载镜像、删除镜像
1、查看镜像
查看镜像命令/
docker images
查看镜像帮助命令
docker images --help
列出所有镜像
docker images -a
列出镜像ID
docker images -q
列出所有镜像ID
docker images -aq
2、搜索镜像
docker search mysql
搜索镜像后,会根据搜索到的镜像名称,描述,星数量等信息展示
docker search --help --查看帮助
根据条件搜索镜像【搜索星星在3000颗以上的MqSQL】
docker search mysql --filter=stars=3000
3、下载镜像 docker pull
下载MySQL镜像,没有指定版本号的情况下,会下载最新的MqSQL版本
docker pull mysql
下载指定版本的Mysql镜像
docker pull mysql:5.7
4、删除镜像 docker rmi -f
删除指定ID的镜像
docker rmi -f c20987f18b13
删除指定查询范围的镜像
docker rmi -f $(docker images -aq)
上述指令会删除所有镜像,他的条件是 docker images -aq
我的练习指令如下:
[root@localhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEhello-world latest feb5d9fea6a5 6 months ago 13.3kB[root@localhost ~]# docker images --helpUsage: docker images [OPTIONS] [REPOSITORY[:TAG]]List imagesOptions: -a, --all Show all images (default hides intermediate images) --digests Show digests -f, --filter filter Filter output based on conditions provided --format string Pretty-print images using a Go template --no-trunc Don't truncate output -q, --quiet Only show image IDs[root@localhost ~]# docker images -aREPOSITORY TAG IMAGE ID CREATED SIZEhello-world latest feb5d9fea6a5 6 months ago 13.3kB[root@localhost ~]# docker images -qfeb5d9fea6a5[root@localhost ~]# docker images -aqfeb5d9fea6a5[root@localhost ~]# docker search mysqlNAME DESCRIPTION STARS OFFICIAL AUTOMATEDmysql MySQL is a widely used, open-source relation… 12325 [OK] mariadb MariaDB Server is a high performing open sou… 4739 [OK] mysql/mysql-server Optimized MySQL Server Docker images. Create… 915 [OK]percona Percona Server is a fork of the MySQL relati… 572 [OK] phpmyadmin phpMyAdmin - A web interface for MySQL and M… 487 [OK] mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr… 93 centos/mysql-57-centos7 MySQL 5.7 SQL database server 92 bitnami/mysql Bitnami MySQL Docker Image 67 [OK]databack/mysql-backup Back up mysql databases to... anywhere! 58 ubuntu/mysql MySQL open source fast, stable, multi-thread… 28 circleci/mysql MySQL is a widely used, open-source relation… 25 mysql/mysql-router MySQL Router provides transparent routing be… 23 centos/mysql-56-centos7 MySQL 5.6 SQL database server 22 google/mysql MySQL server for Google Compute Engine 21 [OK]vmware/harbor-db Mysql container for Harbor 10 mysqlboy/docker-mydumper docker-mydumper containerizes MySQL logical … 3 mysqlboy/mydumper mydumper for mysql logcial backups 3 bitnami/mysqld-exporter 2 ibmcom/mysql-s390x Docker image for mysql-s390x 1 mysql/mysql-operator MySQL Operator for Kubernetes 0 mysqlboy/elasticsearch 0 mysqleatmydata/mysql-eatmydata 0 ibmcom/tidb-ppc64le TiDB is a distributed NewSQL database compat… 0 mirantis/mysql 0 cimg/mysql 0 [root@localhost ~]# docker search --helpUsage: docker search [OPTIONS] TERMSearch the Docker Hub for imagesOptions: -f, --filter filter Filter output based on conditions provided --format string Pretty-print search using a Go template --limit int Max number of search results (default 25) --no-trunc Don't truncate output[root@localhost ~]# docker search --filter=stars=3000 mysqlNAME DESCRIPTION STARS OFFICIAL AUTOMATEDmysql MySQL is a widely used, open-source relation… 12325 [OK] mariadb MariaDB Server is a high performing open sou… 4739 [OK] [root@localhost ~]# docker search mysql --filter=stars=3000 NAME DESCRIPTION STARS OFFICIAL AUTOMATEDmysql MySQL is a widely used, open-source relation… 12325 [OK] mariadb MariaDB Server is a high performing open sou… 4739 [OK] [root@localhost ~]# docker pull --helpUsage: docker pull [OPTIONS] NAME[:TAG|@DIGEST]Pull an image or a repository from a registryOptions: -a, --all-tags Download all tagged images in the repository --disable-content-trust Skip image verification (default true) --platform string Set platform if server is multi-platform capable -q, --quiet Suppress verbose output[root@localhost ~]# docker pull mysqlUsing default tag: latestlatest: Pulling from library/mysql72a69066d2fe: Pull complete 93619dbc5b36: Pull complete 99da31dd6142: Pull complete 626033c43d70: Pull complete 37d5d7efb64e: Pull complete ac563158d721: Pull complete d2ba16033dad: Pull complete 688ba7d5c01a: Pull complete 00e060b6d11d: Pull complete 1c04857f594f: Pull complete 4d7cfa90e6ea: Pull complete e0431212d27d: Pull complete Digest: sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709Status: Downloaded newer image for mysql:latestdocker.io/library/mysql:latest[root@localhost ~]# docker pull mysql:5.75.7: Pulling from library/mysql72a69066d2fe: Already exists 93619dbc5b36: Already exists 99da31dd6142: Already exists 626033c43d70: Already exists 37d5d7efb64e: Already exists ac563158d721: Already exists d2ba16033dad: Already exists 0ceb82207cd7: Pull complete 37f2405cae96: Pull complete e2482e017e53: Pull complete 70deed891d42: Pull complete Digest: sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94Status: Downloaded newer image for mysql:5.7docker.io/library/mysql:5.7[root@localhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEmysql 5.7 c20987f18b13 3 months ago 448MBmysql latest 3218b38490ce 3 months ago 516MBhello-world latest feb5d9fea6a5 6 months ago 13.3kB[root@localhost ~]# docker rmi --helpUsage: docker rmi [OPTIONS] IMAGE [IMAGE...]Remove one or more imagesOptions: -f, --force Force removal of the image --no-prune Do not delete untagged parents[root@localhost ~]# docker rmi -f c20987f18b13Untagged: mysql:5.7Untagged: mysql@sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94Deleted: sha256:c20987f18b130f9d144c9828df630417e2a9523148930dc3963e9d0dab302a76Deleted: sha256:6567396b065ee734fb2dbb80c8923324a778426dfd01969f091f1ab2d52c7989Deleted: sha256:0910f12649d514b471f1583a16f672ab67e3d29d9833a15dc2df50dd5536e40fDeleted: sha256:6682af2fb40555c448b84711c7302d0f86fc716bbe9c7dc7dbd739ef9d757150Deleted: sha256:5c062c3ac20f576d24454e74781511a5f96739f289edaadf2de934d06e910b92[root@localhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEmysql latest 3218b38490ce 3 months ago 516MBhello-world latest feb5d9fea6a5 6 months ago 13.3kB[root@localhost ~]# docker rmi -f $(docker images -aq)Untagged: mysql:latestUntagged: mysql@sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709Deleted: sha256:3218b38490cec8d31976a40b92e09d61377359eab878db49f025e5d464367f3bDeleted: sha256:aa81ca46575069829fe1b3c654d9e8feb43b4373932159fe2cad1ac13524a2f5Deleted: sha256:0558823b9fbe967ea6d7174999be3cc9250b3423036370dc1a6888168cbd224dDeleted: sha256:a46013db1d31231a0e1bac7eeda5ad4786dea0b1773927b45f92ea352a6d7ff9Deleted: sha256:af161a47bb22852e9e3caf39f1dcd590b64bb8fae54315f9c2e7dc35b025e4e3Deleted: sha256:feff1495e6982a7e91edc59b96ea74fd80e03674d92c7ec8a502b417268822ffDeleted: sha256:8805862fcb6ef9deb32d4218e9e6377f35fb351a8be7abafdf1da358b2b287baDeleted: sha256:872d2f24c4c64a6795e86958fde075a273c35c82815f0a5025cce41edfef50c7Deleted: sha256:6fdb3143b79e1be7181d32748dd9d4a845056dfe16ee4c827410e0edef5ad3daDeleted: sha256:b0527c827c82a8f8f37f706fcb86c420819bb7d707a8de7b664b9ca491c96838Deleted: sha256:75147f61f29796d6528486d8b1f9fb5d122709ea35620f8ffcea0e0ad2ab0cd0Deleted: sha256:2938c71ddf01643685879bf182b626f0a53b1356138ef73c40496182e84548aaDeleted: sha256:ad6b69b549193f81b039a1d478bc896f6e460c77c1849a4374ab95f9a3d2cea2Untagged: hello-world:latestUntagged: hello-world@sha256:bfea6278a0a267fad2634554f4f0c6f31981eea41c553fdf5a83e95a41d40c38Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412[root@localhost ~]#
View Code
容器命令
在容器命令之前,先说个考点,有了镜像,我们就可以创建容器了
首先我们先下载个centos 镜像
docker pull centos
1、新建一个名字为:mycentos 的容器并运行它
docker run -it --name=mycentos centos:latest /bin/bash-i 运行容器-t 容器启动后进入该容器执行命令,加入这两个参数,容器创建就能登录进去-name 为创建的容器命名
-v 表示目录的映射关系 本地目录和docker容器目录映射起来 前面宿主机目录,后者是容器的目录,可以使用多个-v 注意:最好做目录映射,在宿主机上面修改文件,然后共享到容器中
-d 在run后面加上-d参数,则会创建一个守护进程在后台运行(这样创建后不会自动登录容器,如果只加-it聚会在创建容器后进入容器)
-p 标识端口映射,前者宿主机端口,后者是容器的映射端口,可以使用多个-p做多个端口映射
-P 随机分配端口
–dns 8.8.8.8 指定容器使用的DNS,默认和宿主机一样
–dns-search example.com 指定容器的DNS搜索的域名,默认和宿主机一致
-h “host——001” 指定容器的hostname
-e username=‘cat’ 设置环境变量
–env-file=[] 从指定文件读入环境变量
–cpuset=“0-2” or --cpuset=“0,1,2” 绑定容器到指定CPU运行
-m 设置容器使用内存大小
–net=“bridge” 指定容器的网络连接类型,支持:bridge/host/none/container四种类型
–link=[] 添加连接到另一个容器
2、退出容器且容器停止运行
exit
如果要退出容器但不想让容器停止运行,可以使用快捷键,ctrl+p+q
使用快捷键后,我们可以看到我们的容器还是在运行的,如下,docker ps
3、查看当前运行的容器
docker ps
4、查看容器
docker ps -l --查看最近一次运行的容器docker ps -a --查看全部容器
5、查看已经关闭的容器
docker ps -f status=exited
6、停止运行的容器
docker stop 容器ID 平滑关闭docker kill 容器ID 强制关闭
7、重启容器
docker restart 容器名称OR容器ID
8、查看容器内运行的进程
docker top 容器名 or 容器ID
9、查看容器日志
-t 显示时间-f 追加查看–tail 看最后几条 n是几条
docker logs -t -f 容器ID(or 容器名称)docker logs -f -t db950b0be73a
docker logs -t -f --tail n 容器ID(or 容器名称)n是显示几条
10、删除容器
docker rm 容器名称 OR 容器ID 容器必须要关闭docker rm -f 容器名称 OR 容器ID 强制删除容器(运行和未运行的)
11、删除全部正在运行的容器
docker rm -f $(docker ps -q) -q 是运行容器的容器ID
12、启动一个已存在的容器
启动一个已存在的容器
docker start 容器IDdocker restart 容器ID
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~