docker 容器的常用命令操作

1: 查看当前运行的容器 

[root@localhost util-linux-2.24]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                  NAMES
e899b82a5a9e        nginx               "nginx -g 'daemon of   49 minutes ago      Up 7 minutes        0.0.0.0:8080->80/tcp   happy_elion         
[root@localhost util-linux-2.24]# 


2: 停止当前容器

[root@localhost util-linux-2.24]# docker stop e899b82a5a9e
e899b82a5a9e
[root@localhost util-linux-2.24]# docker ps -a 
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                     PORTS               NAMES
e899b82a5a9e        nginx               "nginx -g 'daemon of   50 minutes ago      Exited (0) 8 seconds ago                       happy_elion         
[root@localhost util-linux-2.24]# 


3: 启动当前容器

[root@localhost util-linux-2.24]# docker  ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                      PORTS               NAMES
e899b82a5a9e        nginx               "nginx -g 'daemon of   51 minutes ago      Exited (0) 50 seconds ago                       happy_elion         
[root@localhost util-linux-2.24]# 
[root@localhost util-linux-2.24]# docker start e899b82a5a9e
e899b82a5a9e
[root@localhost util-linux-2.24]# 


4: 进行日志查询

[root@localhost util-linux-2.24]# docker logs -f e899b82a5a9e
192.168.19.128 - - [01/Mar/2018:16:05:12 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0" "-"
2018/03/01 16:05:13 [error] 6#6: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 192.168.19.128, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.19.128:8080"
192.168.19.128 - - [01/Mar/2018:16:05:13 +0000] "GET /favicon.ico HTTP/1.1" 404 169 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0" "-"
2018/03/01 16:05:13 [error] 6#6: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 192.168.19.128, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.19.128:8080"
192.168.19.128 - - [01/Mar/2018:16:05:13 +0000] "GET /favicon.ico HTTP/1.1" 404 169 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0" "-"

5: 进入容器

[root@localhost util-linux-2.24]# docker exec -it e899b82a5a9e /bin/bash 
root@e899b82a5a9e:/# 
root@e899b82a5a9e:/# 

6: 进入容器后 已nginx为例,查询配置等信息

root@e899b82a5a9e:/# nginx -? 
nginx version: nginx/1.13.9
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]


Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /etc/nginx/)
  -c filename   : set configuration file (default: /etc/nginx/nginx.conf)
  -g directives : set global directives out of configuration file

root@e899b82a5a9e:/# 


7: 删除容器

[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                      PORTS               NAMES
e899b82a5a9e        nginx               "nginx -g 'daemon of   About an hour ago   Exited (0) 44 minutes ago                       happy_elion         
[root@localhost ~]# 
[root@localhost ~]# docker rm e899b82a5a9e


8: 新建容器

[root@localhost ~]# docker run -d -p 8080:80 nginx
b35721c1678f70dc246e0d3a6524558e420e9efc878cd0503ce9157cec28fad9
[root@localhost ~]# docker run -d -p 8081:80 nginx
af8c2df7d378ab9d4238975cc46d2230352c56f4e085ee15eb74bb4f60d26adb
[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                  NAMES
af8c2df7d378        nginx               "nginx -g 'daemon of   7 seconds ago       Up 5 seconds        0.0.0.0:8081->80/tcp   elated_sammet       
b35721c1678f        nginx               "nginx -g 'daemon of   16 seconds ago      Up 13 seconds       0.0.0.0:8080->80/tcp   focused_euclid      
[root@localhost ~]# 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值