Docker基本命令说明

docker基础命令的说明。

Docker常用命令的说明

docker pull

\ 下载一个Image

1
2
3
4
5
6
[root@localhost ~]# docker pull nginx:lastest  
Using default tag: latest
Trying to pull repository docker.io/library/nginx ...
sha256:0fb320e2a1b1620b4905facb3447e3d84ad36da0b2c8aa8fe3a5a81d1187b884: Pulling from docker.io/library/nginx
Digest: sha256:0fb320e2a1b1620b4905facb3447e3d84ad36da0b2c8aa8fe3a5a81d1187b884
Status: Image is up to date for docker.io/nginx:latest

docker push

\ 上传一个Image

docker run

\ 启动一个Container

1
[root@localhost ~]# docker run nginx

docker kill

\ 结束一个Container

1
[root@localhost ~]# docker kill flamboyant_thompson

docker system prune

\ 清理Docker的无用文件,包括未使用的容器和不具有Dangling的镜像(不具有启动能力的Image)

docker images

\ 列出所有的docker images

1
2
3
4
5
[root@localhost ~]# docker images
ONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1cca834eb80c nginx "nginx -g 'daemon ..." 57 seconds ago Up 56 seconds 80/tcp flamboyant_thompson
769aefe85e29 achabill/lh-toolkit "dockerize -wait t..." 3 hours ago Up 3 hours 0.0.0.0:8080->8080/tcp sad_payne
93431e5f2f66 achabill/lh-mysql:latest "docker-entrypoint..." 3 hours ago Up 3 hours 0.0.0.0:3308->3306/tcp brave_mcclintock

\ 搜索特定名称的image

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
[root@localhost ~]# docker search nginx
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/nginx Official build of Nginx. 8564 [OK]
docker.io docker.io/nginx Official build of Nginx. 8564 [OK]
docker.io docker.io/jwilder/nginx-proxy Automated Nginx reverse proxy for docker c... 1334 [OK]
docker.io docker.io/jwilder/nginx-proxy Automated Nginx reverse proxy for docker c... 1334 [OK]
docker.io docker.io/richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable ... 547 [OK]
docker.io docker.io/richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable ... 547 [OK]
docker.io docker.io/jrcs/letsencrypt-nginx-proxy-companion LetsEncrypt container to use with nginx as... 367 [OK]
docker.io docker.io/jrcs/letsencrypt-nginx-proxy-companion LetsEncrypt container to use with nginx as... 367 [OK]
docker.io docker.io/kong Open-source Microservice & API Management ... 187 [OK]
docker.io docker.io/kong Open-source Microservice & API Management ... 187 [OK]
docker.io docker.io/webdevops/php-nginx Nginx with PHP-FPM 103 [OK]
docker.io docker.io/webdevops/php-nginx Nginx with PHP-FPM 103 [OK]
docker.io docker.io/kitematic/hello-world-nginx A light-weight nginx container that demons... 98
docker.io docker.io/kitematic/hello-world-nginx A light-weight nginx container that demons... 98
docker.io docker.io/bitnami/nginx Bitnami nginx Docker Image 50 [OK]
docker.io docker.io/bitnami/nginx Bitnami nginx Docker Image 50 [OK]
docker.io docker.io/zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server ... 50 [OK]
docker.io docker.io/zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server ... 50 [OK]
docker.io docker.io/1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 35 [OK]
docker.io docker.io/1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 35 [OK]
docker.io docker.io/linuxserver/nginx An Nginx container, brought to you by Linu... 35
docker.io docker.io/linuxserver/nginx An Nginx container, brought to you by Linu... 35
docker.io docker.io/tobi312/rpi-nginx NGINX on Raspberry Pi / armhf 19 [OK]
docker.io docker.io/tobi312/rpi-nginx NGINX on Raspberry Pi / armhf 19 [OK]
docker.io docker.io/nginxdemos/nginx-ingress NGINX Ingress Controller for Kubernetes . ... 11
docker.io docker.io/nginxdemos/nginx-ingress NGINX Ingress Controller for Kubernetes . ... 11
docker.io docker.io/blacklabelops/nginx Dockerized Nginx Reverse Proxy Server. 9 [OK]
docker.io docker.io/blacklabelops/nginx Dockerized Nginx Reverse Proxy Server. 9 [OK]
docker.io docker.io/wodby/drupal-nginx Nginx for Drupal container image 9 [OK]
docker.io docker.io/wodby/drupal-nginx Nginx for Drupal container image 9 [OK]
docker.io docker.io/webdevops/nginx Nginx container 8 [OK]
docker.io docker.io/webdevops/nginx Nginx container 8 [OK]
docker.io docker.io/centos/nginx-18-centos7 Platform for running nginx 1.8 or building... 6
docker.io docker.io/centos/nginx-18-centos7 Platform for running nginx 1.8 or building... 6
docker.io docker.io/nginxdemos/hello NGINX webserver that serves a simple page ... 6 [OK]
docker.io docker.io/nginxdemos/hello NGINX webserver that serves a simple page ... 6 [OK]
docker.io docker.io/1science/nginx Nginx Docker images that include Consul Te... 4 [OK]
docker.io docker.io/1science/nginx Nginx Docker images that include Consul Te... 4 [OK]
docker.io docker.io/centos/nginx-112-centos7 Platform for running nginx 1.12 or buildin... 3
docker.io docker.io/behance/docker-nginx Provides base OS, patches and stable nginx... 2 [OK]
docker.io docker.io/behance/docker-nginx Provides base OS, patches and stable nginx... 2 [OK]
docker.io docker.io/pebbletech/nginx-proxy nginx-proxy sets up a container running ng... 2 [OK]
docker.io docker.io/pebbletech/nginx-proxy nginx-proxy sets up a container running ng... 2 [OK]
docker.io docker.io/toccoag/openshift-nginx Nginx reverse proxy for Nice running on sa... 1 [OK]
docker.io docker.io/toccoag/openshift-nginx Nginx reverse proxy for Nice running on sa... 1 [OK]
docker.io docker.io/travix/nginx NGinx reverse proxy 1 [OK]
docker.io docker.io/travix/nginx NGinx reverse proxy 1 [OK]
docker.io docker.io/ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 0 [OK]
docker.io docker.io/mailu/nginx Mailu nginx frontend 0 [OK]
docker.io docker.io/mailu/nginx Mailu nginx frontend 0 [OK]
redhat.com registry.access.redhat.com/3scale-amp20-beta/apicast-gateway 3scale's API gateway (APIcast) is an OpenR... 0
redhat.com registry.access.redhat.com/3scale-amp20/apicast-gateway 3scale's API gateway (APIcast) is an OpenR... 0
redhat.com registry.access.redhat.com/rhamp10/apicast-gateway 3scale's API gateway (APIcast) is an OpenR... 0
redhat.com registry.access.redhat.com/rhmap43/wildcard-proxy RHMAP Docker image that provides mapping a... 0
redhat.com registry.access.redhat.com/rhmap44/wildcard-proxy RHMAP Docker image that provides mapping a... 0
redhat.com registry.access.redhat.com/rhmap45/wildcard-proxy RHMAP image that provides mapping and prox... 0
redhat.com registry.access.redhat.com/rhmap46/wildcard-proxy RHMAP image that provides mapping and prox... 0
redhat.com registry.access.redhat.com/rhscl/nginx-110-rhel7 Nginx container image that delivers an ngi... 0
redhat.com registry.access.redhat.com/rhscl/nginx-112-rhel7 Nginx is a web server and a reverse proxy ... 0
redhat.com registry.access.redhat.com/rhscl/nginx-16-rhel7 Nginx 1.6 server and a reverse proxy server 0
redhat.com registry.access.redhat.com/rhscl/nginx-18-rhel7 Nginx 1.8 server and a reverse proxy server 0

docker ps

\ 列出docker正在运行的Container

1
2
3
4
5
[root@localhost ~]# docker ps 
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1cca834eb80c nginx "nginx -g 'daemon ..." 57 seconds ago Up 56 seconds 80/tcp flamboyant_thompson
769aefe85e29 achabill/lh-toolkit "dockerize -wait t..." 3 hours ago Up 3 hours 0.0.0.0:8080->8080/tcp sad_payne
93431e5f2f66 achabill/lh-mysql:latest "docker-entrypoint..." 3 hours ago Up 3 hours 0.0.0.0:3308->3306/tcp brave_mcclintock

docker container ls

\ 列出所有存在的Container,包括为运行的和未使用的

1
2
3
4
5
[root@localhost ~]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1cca834eb80c nginx "nginx -g 'daemon ..." 57 seconds ago Up 56 seconds 80/tcp flamboyant_thompson
769aefe85e29 achabill/lh-toolkit "dockerize -wait t..." 3 hours ago Up 3 hours 0.0.0.0:8080->8080/tcp sad_payne
93431e5f2f66 achabill/lh-mysql:latest "docker-entrypoint..." 3 hours ago Up 3 hours 0.0.0.0:3308->3306/tcp brave_mcclintock

docker run -dt

\ 运行一个image,给予一个Terminal,放入后台,返回一个ContainerID

1
2
[root@localhost ~]# docker run -dt -p 80:80 nginx
1cca834eb80cd8467dec6d103bf9072adfb55d8cfb2fdc257af548dc25917868

docker run -it

\ 运行一个image,给予一个Terminal,直接进入Container

1
[root@localhost ~]# docker run -it -p 80:80 nginx

docker run

\ 运行一个image,如果本地没有自动到docker仓库检索

1
[root@localhost ~]# docker run nginx

docker run -p

\ 运行一个image,指定port的映射关系

1
[root@localhost ~]# docker run -p 80:80 nginx

docker attach

\ 进入到某一个Container内部,如果没有shell,无法操作, 输出一片空白

1
2
[root@localhost ~]# docker attach flamboyant_thompson
[root@d4a75f165ce6 /]#
文章目录
  1. 1. Docker常用命令的说明
    1. 1.1. docker pull
    2. 1.2. docker push
    3. 1.3. docker run
    4. 1.4. docker kill
    5. 1.5. docker system prune
    6. 1.6. docker images
    7. 1.7. docker search
    8. 1.8. docker ps
    9. 1.9. docker container ls
    10. 1.10. docker run -dt
    11. 1.11. docker run -it
    12. 1.12. docker run
    13. 1.13. docker run -p
    14. 1.14. docker attach