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 ~]#