【CentOS7】【docker】常⽤操作命令⽬录
前⾔
CentOS Linux release 7.9.2009
Docker version 19.03.14
先拉取镜像 -> 通过镜像创建容器 -> 启动、关闭、重启容器 -> 再登录到容器的控制台进⾏操作
查镜像
可视化查镜像
在 上搜索镜像。
docker命令查镜像
这种⽅式查镜像时,结果⽐较糙,不能查看每个镜像有哪些tag。
shell> docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, open-source relation… 10637 [OK]
mariadb MariaDB Server is a high performing open sou… 3991 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 779 [OK] percona Percona Server is a fork of the MySQL relati… 528 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server 87
mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr (79)
centurylink/mysql Image containing mysql. Optimized to be link… 59 [OK] bitnami/mysql Bitnami MySQL Docker Image 49 [OK]
deitch/mysql-backup REPLACED! Please use hub.docker/r… 41 [OK] databack/mysql-backup Back up mysql anywhere! 41
prom/mysqld-exporter 37 [OK]
tutum/mysql Base docker image to run a MySQL database se (35)
schickling/mysql-backup-s3 Backup MySQL to S3 (supports 29 [OK] linuxserver/mysql A Mysql container, brought to you by LinuxSe (27)
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 (18)
arey/mysql-client Run a MySQL client from a docker container 17 [OK]
fradelg/mysql-cron-backup MySQL/MariaDB database backup using 12 [OK] yloeffler/mysql-backup This image runs mysqldump to backup 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] jelastic/mysql An image of the MySQL database server mainta (1)
widdpim/mysql-client Dockerized MySQL Client (5.7) including Curl… 1 [OK]
镜像操作
拉取镜像
shell> docker pull 镜像名字:tag
tag 不写时,默认为latest
⽐如:
shell> docker pull redis
等价于
shell> docker pull redis:latest
指定tag的⽰例:
shell> docker pull redis:6.2.1
shell> docker pull redis:6.2.1-alpine
shell> docker pull redis:6.2.1-alpine3.13
shell> docker pull redis:6.2-buster
查看本地已拉取的镜像
shell> docker images -a --no-trunc
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest sha256:a617c1c92774952d26fb87ba9a32fdc4d424fb7be02bbc84d6fefb517f3d4c6c 9 days ago 105MB
hello-world latest sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726 2 weeks ago 13.3kB rabbitmq 3-management sha256:800294d91e3181d14a3b4920bbf348b5d407fc603f91f2b6310ea07284d8f6d2 2 months ago 198MB mysql 5.6.40 sha256:50328380b2b44db6826909771a7059dbea575af52
bc242dacd4f6e365f3592b7 2 years ago 256MB
或者:
shell> docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest a617c1c92774 9 days ago 105MB
hello-world latest d1165f221234 2 weeks ago 13.3kB
rabbitmq 3-management 800294d91e31 2 months ago 198MB
mysql 5.6.40 50328380b2b4 2 years ago 256MB
区别在于IMAGE ID。简写的IMAGE ID也有效。
删除镜像
使⽤ docker rmi 删除镜像:
shell> docker rmi --help
Usage: docker rmi [OPTIONS] IMAGE []
Remove one or more images
Options:
-f, --force Force removal of the image
--no-prune Do not delete untagged parents
⽰例:
# 通过镜像名字:tag 定位镜像
shell> docker rmi mysql:5.6.40
Untagged: mysql:5.6.40
Untagged: mysql@sha256:4902cd80486dca889205576a698a3e6534376ef6d8b94ef9fc9c61e891f1cd15
Deleted: sha256:50328380b2b44db6826909771a7059dbea575af52bc242dacd4f6e365f3592b7
Deleted: sha256:697d89d941b59add425566c6c0c60d10bb4b21bf6f86ef7ddccb94ddae6cf20a
Deleted: sha256:c3e5f383007dbd1b8a4c327429272f3ab98cd183b6c17dbe281c0db2af0c5af3
Deleted: sha256:27d9bcc11f4e4db5f8b4327ec3aa29fd323e36a6c8a47bc17b9893981a0f4e56
Deleted: sha256:578ecce506d2e9293a0d3cd898345901dec4aaa3650f6e98235617838968f86b
Deleted: sha256:431c1168801316fa15f53294aa6769b97686371b056c9415672f700b0308bf2b
Deleted: sha256:bff479cb74c3b47307144d06e2a36f81ff96ee897afe374ef1c6ff6d83776738
Deleted: sha256:202db300227b8c870b421aa0a0a11b44cb916401ef3a34bcc2a5efcb30a3ea78
Deleted: sha256:20f3dff2c1b6f8409b53e4e203132f7ebb2dfd7dc612d87e4a93302a5a8f5c1a
docker重启容器命令Deleted: sha256:3131a4917b53634699929d8ff7e2b2bd9469f3f5ab08daf41d1c6b90e0f18b44
Deleted: sha256:9996a153********cb2177cfdbe8fcb9f65124142edb9b1d3550f3eb87360676
Deleted: sha256:cdb3f9544e4c61d45da1ea44f7d92386639a052c620d1550376f22f5b46981af
# 通过镜像ID 定位镜像
shell> docker rmi 50328380b2b4
# 通过镜像的长ID 定位镜像
shell> docker rmi 50328380b2b44db6826909771a7059dbea575af52bc242dacd4f6e365f3592b7
删除镜像的限制:
docker会检查该镜像是否已经创建过容器。如果该镜像已经创建过容器,则不能删除。
先删除对应的容器,再删除镜像。
创建容器
创建但不运⾏容器
shell> docker create [OPTIONS] IMAGE [COMMAND] []
例如:
shell> docker create --name redis1 -p 6379:6379 redis --requirepass "redispassword"
创建并运⾏容器
shell> docker run [OPTIONS] IMAGE [COMMAND] []
例如:
shell> docker run -d --name redis1 -p 6379:6379 redis --requirepass "redispassword"
docker run [-d --name redis1 -p 6379:6379] redis --requirepass "redispassword" []中是 OPTIONS
docker run -d --name redis1 -p 6379:6379 [redis] --requirepass "redispassword" []中是 IMAGE
docker run -d --name redis1 -p 6379:6379 redis [--requirepass "redispassword"] []中是 ARG
管理容器
查看运⾏着的容器
使⽤ docker ps 查看正在运⾏的容器:
shell> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
566cc23c3aa1 redis "docker-entrypoint.s…" 4 hours ago Up 2 hours 0.0.0.0:6379->6379/tcp redis1
9ac952ee4921 rabbitmq:3-management "docker-entrypoint.s…" 4 hours ago Up 2 hours 4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, 15 671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp rabbitmq1
想看容器启动时执⾏的命令:
shell> docker ps --no-trunc
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
566cc23c3aa1af21cd55c8c87bf80b7b7318914cf84defc9ec0b36aa815fc0d1 redis "docker-entrypoint.sh --requirepass redispass" 4 hours ag o Up 2 hours 0.0.0.0:6379->6379/tcp redis1
9ac952ee49214c5e3ec43ef1c21e0580cf65439edc23cf4f1712a0572e41df20 rabbitmq:3-management "docker-entrypoint.sh rabbitmq-server" 4 h ours ago Up 2 hours 4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp rabbitmq 1
查看本地已创建的容器(运⾏着的+未运⾏着的)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论