Docker实用命令介绍

Posted will-xz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker实用命令介绍相关的知识,希望对你有一定的参考价值。

Docker实用命令介绍

 

1. docker启动、关闭、停止

╭─wil-xz in ~                                                                                                                                    12:15:44
╰─?(?﹏?、)?  service docker restart 
Redirecting to
/bin/systemctl restart docker.service
╭─wil-xz in ~                                                                                                                                    12:15:44
╰─?(?﹏?、)?  service docker stop 
Redirecting to
/bin/systemctl stop docker.service
╭─wil-xz in ~                                                                                                                                    12:15:44
╰─?(?﹏?、)?  service docker start 
Redirecting to
/bin/systemctl start docker.service

2. 查看当前docker的所有镜像。docker images

╭─wil-xz in ~                                                                                                                                    12:15:44
╰─?(?﹏?、)?  docker images
REPOSITORY                                      TAG                 IMAGE ID            CREATED             SIZE
will3369/php5.6                                 latest              838e8980cb1d        2 days ago          506MB

3. 查找某个服务环境的镜像。docker search php

╭─wil-xz in ~                                                                                                                                    12:16:31
╰─(?? ??_??)?  docker search php
NAME                                                      DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
php                                                       While designed for web development, the PHP …   3992                [OK]                
phpmyadmin/phpmyadmin                                     A web interface for mysql and MariaDB.          644                                     [OK]

4. 拉取镜像。docker pull php

╭─wil-xz in ~                                                                                                                                    12:17:57
╰─o(≧口≦)o  docker pull php
Using default tag: latest
latest: Pulling from library/php
Digest: sha256:417dd4c0f12e5cd3f284b48b5ea6b13d38eda8eacc9008774637df389590d6da
Status: Image is up to date for php:latest

5. 运行容器。docker run -tid --name container_name php 

╭─wil-xz in ~                                                                                                                                    12:18:08
╰─ε=ε=ヾ(;?д?)/  docker run -tid --name php_c php         
c77ba90444b478444bcb7dc27205c7980bbe196b101fb08c3c404f2b813e156e

6. 查看容器。docker ps 或 docker ps -a,docker ps 查看正在运行的容器,docker ps -a查看所有容器即包括停止的容器跟启动失败的容器。

╭─wil-xz in ~                                                                                                                                    12:18:54
╰─╰(*°▽°*)╯  docker ps
CONTAINER ID        IMAGE                                               COMMAND                  CREATED             STATUS              PORTS                              NAMES
c77ba90444b4        php                                                 "docker-php-entrypoi…"   13 seconds ago      Up 20 seconds           

7. 查看容器报错日志。docker logs 容器名,假如容器没有启动成功,即,docker run后发现docker ps没有看到正在运行的容器,可以通过此命令查看报错信息。

╭─wil-xz in ~                                                                                                                                    12:20:30
╰─(*′?д?)?  docker logs cdbmaster
2018-10-31 08:38:20 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-10-31 08:38:20 0 [Note] mysqld (mysqld 5.6.41-log) starting as process 1 ...
2018-10-31 08:38:20 1 [Note] Plugin FEDERATED is disabled.
2018-10-31 08:38:20 1 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-10-31 08:38:20 1 [Note] InnoDB: The InnoDB memory heap is disabled

8. 查看容器环境。docker inspect 容器名

技术分享图片

9. 查看容器内运行的进程。docker top 容器名

╭─wil-xz in ~                                                                                                                                    12:21:12
╰─(?3?)~?  docker top php_c
PID                 USER                TIME                COMMAND
28858               root                0:00                php -a

10. 查看容器绑定端口。docker port 容器名

╭─wil-xz in ~                                                                                                                                    12:22:57
╰─o(≧口≦)o  docker port cmysqlproxy
4040/tcp -> 0.0.0.0:4040

11. 进入容器。 docker exec -it 容器名 bash

╭─wil-xz in ~                                                                                                                                    12:22:58
╰─ヽ(*。>Д<)o゜  docker exec -it php_c bash
[email protected]:/# 

12. 删除容器。docker rm 容器名。删除容器前必须先运行 docker stop 容器名,停止容器。

╭─wil-xz in ~                                                                                                                                    12:23:53
╰─ヾ(;?;Д;?;)??  docker stop php_c
php_c

╭─wil-xz in ~                                                                                                                                    12:24:11
╰─ヾ(;?;Д;?;)??  docker rm php_c
php_c

13. 删除所有容器。docker rm $(docker ps -a -q)。前提必须停止所有容器,即运行docker stop $(docker ps -a -q)。

╭─wil-xz in ~                                                                                                                                    12:24:22
╰─?(?﹏?、)?  docker rm $(docker ps -a -q)

14. 删除镜像。docker rmi 镜像名

╭─wil-xz in ~                                                                                                                                    12:25:33
╰─(?3?)~?  docker rmi php
Untagged: php:latest
Untagged: [email protected]:417dd4c0f12e5cd3f284b48b5ea6b13d38eda8eacc9008774637df389590d6da
Deleted: sha256:df1b7c730f916447514631a9f9847fc39d6f55cc2525693700623939aa946b78

 






以上是关于Docker实用命令介绍的主要内容,如果未能解决你的问题,请参考以下文章

markdown [Docker] Docker片段列表和命令#linux #docker #snippets

Android 实用代码片段

Android 实用代码片段

30 段 Python 实用代码

Docker实用命令手册

Docker实用命令手册