码迷,mamicode.com
首页 > 其他好文 > 详细

Docker实用命令介绍

时间:2018-11-03 13:56:23      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:失败   res   mys   count   图片   日志   stat   技术   tin   

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
root@c77ba90444b4:/# 

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: php@sha256:417dd4c0f12e5cd3f284b48b5ea6b13d38eda8eacc9008774637df389590d6da
Deleted: sha256:df1b7c730f916447514631a9f9847fc39d6f55cc2525693700623939aa946b78

 

Docker实用命令介绍

标签:失败   res   mys   count   图片   日志   stat   技术   tin   

原文地址:https://www.cnblogs.com/will-xz/p/9900248.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!