Docker common commands
1. Help command
1. View the currentdocker
version
docker version
2. Viewdocker
’s detailed information
docker info
3.docker
’s help command
docker --help
2. Mirror command
Mirror command | illustrate |
---|---|
docker images |
List mirrors for localhost |
docker search 镜像名称 |
Search for images fromdocker HUB |
docker pull 镜像名称 |
Download the image fromdocker HUB |
docker rmi 镜像名称 |
Delete local image |
docker images --help
: Viewimages
What commands can we use
docker images -qa
:View all image namesID
Search for an image name
[root@10 vagrant]# docker search tomcat
Search detailed image name information
parameter name | describe |
---|---|
--no-trunc |
Show full description |
--limit |
Paginated display |
-f |
filter conditionsdocker search -f STARS=5 tomcat |
docker search --no-trunc tomcat
分页处理 前5条
docker search --limit 5 tomcat
查找STARS大于5的
docker search --limit SRARS=5 tomcat
3. Download command
`docker pull + image name: version number (without version number, download the latest by default)
eg:
--下载tomcat
docker pull tomcat
--下载Redis
docker pull redis:3.5
--下载centOs7
docker pull centos:centos7
4. Image deletion command
View the command to delete the image
docker rmi --help
--结果
Usage: docker rmi [OPTIONS] IMAGE [IMAGE...]
Remove one or more images
Aliases:
docker image rm, docker image remove, docker rmi
Options:
-f, --force Force removal of the image
--no-prune Do not delete untagged parents
Delete command: delete one or more
docker rmi redis:latest tomcat:latest
--强制删除 -f
docker rmi -f redis:latest tomcat:latest
Delete all image files
docker rmi -f $(docker images -qa)
docker images -qa: 查找所有的docker镜像
2. Container commands
1.Downloadcentos7
docker pull centos:centos7
2. Create and start the container
docker run [OPTIONS] IMAGE [COMMAND]
options | interpretation |
---|---|
--name |
Container new name: Specify a name for the container |
-d |
Run the container in the background and return the container ID, that is, start the guardian container |
-i |
Start the container ininteractive mode, usually used together with-t |
-t |
Reallocate a pseudo input terminal for the container, usually used together with -i |
-P: |
Random port mapping |
-p |
Specified end projection Present or lessFour typesFormat: 1. ip:hostPort:containerPort 2. ip::containerPort 3. hostPort:containerPort 4. containerPort |
interactive container
docker run -it centos /bin/bash
3. List running containers
Check what containers are currently running:
docker ps [OPTIONS]
OPTIONS |
illustrate |
---|---|
-a |
List all currently running containers + those that have been run in history |
-l |
Show recently created containers |
-n |
Display the last n containers created |
--no-trunc |
Do not truncate output |
-q |
Silent mode. Only the container number is displayed |
eg:
--显示所有正在运行容器编号
docker ps -qa
4. Command to exit the container
Exit method | illustrate |
---|---|
exit |
Container stops exiting |
Shortcut key:ctrl+p+q | The container exits, but does not exit |
The first
exit
--退出的结果显示
[root@8f09e627e2e7 /]# exit
exit
[root@10 /]#
Second method: Use shortcut keys
快捷键: ctrl+p+q
如果再次返回:通过 docker exec -it 容器ID
[root@10 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1ca9ce7200aa centos:centos7 "/bin/bash" 3 minutes ago Up 3 minutes reverent_wozniak
8f09e627e2e7 centos:centos7 "/bin/bash" 19 minutes ago Exited (127) 5 minutes ago tender_booth
2c8ea87f45c6 mysql:5.6 "docker-entrypoint.s…" 2 months ago Exited (255) 2 months ago 0.0.0.0:12345->3306/tcp, :::12345->3306/tcp mysql
[root@10 ~]#
5. Start the container
docker start 容器的ID(可以是前面的ID部分输入即可)
Restart container
docker restart 容器部分ID
6. Stop the container
docker stop 容器ID
docker kill 容器ID
7. Container deletion command
docker rm 容器ID
Delete all in batches
docker rm -f $(docker ps -qa)
Use pipe character to delete
docker ps -aq | xargs docker rm
3. Other commands
1. Guardian container
docker run -d 容器名称
Write a simple script, print and run
docker run -d centos:centos7 /bin/bash -c 'while true; do echo hello;sleep 2;done'
--我们查看容器
docker ps
Print logs for this container
docker logs -t -f --tail 3 容器ID
2. View container processes
docker top 容器ID
3. View the details of this container
docker inspect 容器ID
4. File copy
docker cp 容器ID:容器内路径 目的地路径