docker镜像+容器,常用命令
程序员文章站
2024-03-12 17:26:02
...
docker images #查看本机上的所有镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
node 16-alpine3.11 2eac0028bc49 2 weeks ago 113MB
mysql latest c0cdc95609f1 5 weeks ago 556MB
mysql 5.5 d404d78aa797 2 years ago 205MB
#解释
REPOSITORY 镜像的仓库名称
TAG 版本
IMAGE ID 镜像的id
CREATED 创建时间
SIZE 大小
#可选项
-a #列出所有镜像
-p #只显示镜像的id
[[email protected] ~]# docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
node 16-alpine3.11 2eac0028bc49 2 weeks ago 113MB
mysql latest c0cdc95609f1 5 weeks ago 556MB
mysql 5.5 d404d78aa797 2 years ago 205MB
[[email protected] ~]# docker images -q
2eac0028bc49
c0cdc95609f1
d404d78aa797
docker search 搜索镜像
[[email protected] ~]# docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 11008 [OK]
mariadb MariaDB Server is a high performing open sou… 4171 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 817 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server 88
mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr… 86
centurylink/mysql Image containing mysql. Optimized to be link… 59 [OK]
bitnami/mysql Bitnami MySQL Docker Image 52 [OK]
databack/mysql-backup Back up mysql databases to... anywhere! 44
deitch/mysql-backup REPLACED! Please use http://hub.docker.com/r… 41 [OK]
prom/mysqld-exporter 39 [OK]
tutum/mysql Base docker image to run a MySQL database se… 35
linuxserver/mysql A Mysql container, brought to you by LinuxSe… 30
schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic backup… 29 [OK]
centos/mysql-56-centos7 MySQL 5.6 SQL database server 20
circleci/mysql MySQL is a widely used, open-source relation… 20
mysql/mysql-router MySQL Router provides transparent routing be… 19
arey/mysql-client Run a MySQL client from a docker container 17 [OK]
fradelg/mysql-cron-backup MySQL/MariaDB database backup using cron tas… 13 [OK]
yloeffler/mysql-backup This image runs mysqldump to backup data usi… 7 [OK]
genschsa/mysql-employees MySQL Employee Sample Database 7 [OK]
openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 image… 6
devilbox/mysql Retagged MySQL, MariaDB and PerconaDB offici… 3
ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 2 [OK]
widdpim/mysql-client Dockerized MySQL Client (5.7) including Curl… 1 [OK]
jelastic/mysql An image of the MySQL database server mainta… 1
单mysql来说就搜到这么多镜像可以安装了
docker pull 下载镜像
[[email protected] ~]# docker pull redis #docker pull 镜像名
Using default tag: latest
latest: Pulling from library/redis
69692152171a: Already exists
a4a46f2fd7e0: Pull complete
bcdf6fddc3bd: Pull complete
2902e41faefa: Pull complete
df3e1d63cdb1: Pull complete
fa57f005a60d: Pull complete
Digest: sha256:7e2c6181ad5c425443b56c7c73a9cd6df24a122345847d1ea9bb86a5afc76325
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest
docker rmi 删除镜像
[[email protected] ~]# docker rmi d404d78aa797 #docker rmi +镜像id 或者 docker rmi +镜像名称 两种选其一即可
#如删除多个镜像: docker rmi -f 镜像id 镜像id 镜像id
Untagged: mysql:5.5
Untagged: [email protected]:12da85ab88aedfdf39455872fb044f607c32fdc233cd59f1d26769fbf439b045
Deleted: sha256:d404d78aa797c87c255e5ae2beb5d8d0e4d095f930b1f20dc208eaa957477b74
Deleted: sha256:8ae7b3986b745c9cea4ea3789277dbf8543d6caed82c23d1ec19637813376df5
Deleted: sha256:6aaf52074d0d6ec3263af5f53b921a91ba3ddbeb2fece1a82ebe1bc5086c3814
Deleted: sha256:cf0a74866630c5d7ed05927cf981ac93b63ba83407872c9c0fbe0486d5f9806e
Deleted: sha256:e06cee897f9eb6bb5769f93cf6cd0285bb773d7e2bad6dfd5592a8682a6e6740
Deleted: sha256:4354e03e5a414adc57def51226d72fa2d117875a6c9665561a7c0fc85d23c46f
Deleted: sha256:647b973285178c7d4bf022c31baac404e0947d37be8e8e85731de8f7ca7e70e6
Deleted: sha256:c75ab456a585af40ca2ec8488164230deb81a1739d868604cb7b6661c24e37b5
Deleted: sha256:50a75eb6a0b2254fe5d96f999cc2087e72d515c93509a816bbd9ffb707a3b1b0
Deleted: sha256:1ae6616333a66450738a72a75c03bdf0236e0425ba0336ac5cdbe470ab6f4a3e
Deleted: sha256:68e318bd9263aedd19d9d73b051a262fa57e2a16f9c81c8b39163601020cd405
Deleted: sha256:6270adb5794c6987109e54af00ab456977c5d5cc6f1bc52c1ce58d32ec0f15f4
#注意事项:有没有发现有时候无法删除镜像,因为镜像里容器在运行所有无法删除
#删除方法:1,停止容器 2,删除容器 3,删除镜像
容器命令
启动容器
docker run [参数] images
#参数说明
--name 容器名字
-d 后台运行方式
-it 使用交互方式运行,进入容器
-P(大写) 指定容器的端口 -P 8080:8080 主机端口:容器端口
#从容器中退出
[[email protected] /]# exit
exit
[[email protected] /]# #已经返回到本机了
列出所有运行的容器
#当前运行的容器
[[email protected] /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
aad8b1c1f905 registry.cn-hangzhou.aliyuncs.com/sqqdcl/miaosha:latest "/bin/sh -c 'sleep 6…" 2 weeks ago Up 2 weeks 0.0.0.0:7080->7080/tcp, :::7080->7080/tcp
#曾经运行过的容器
[[email protected] /]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
21b099920d65 centos "/bin/bash" 15 minutes ago Exited (0) 3 minutes ago
#docker ps 总结
#列出正在运行的容器 docker ps
#列车正在运行+历史运行过的容器 docker ps -a
#更加直观,可排序 docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}"
删除容器
[[email protected] /]# docker rm 21b099920d65
#如果想强制删除可以 -f docker rm -f [容器名称] 或 [容器id]
启动和停止容器
docker start [容器id] #启动容器
docker stop [容器id] #停止容器
docker restart [容器id] #重启容器
上一篇: java邮件收发功能实现代码