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

【Docker学习之三】Docker查找拉取镜像、启动容器、容器使用

时间:2019-08-25 10:22:21      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:proxy   完成后   book   you   sci   hellip   manage   gre   seconds   

环境
  docker-ce-19.03.1-3.el7.x86_64
  CentOS 7


一、查找、拉取镜像、启动容器
1、查找镜像-docker search
默认查找Docker Hub上的镜像,举例:Docker安装nginx

[root@node105 ~]# docker search nginx
NAME                              DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
nginx                             Official build of Nginx.                        11866               [OK]                
jwilder/nginx-proxy               Automated Nginx reverse proxy for docker con…   1641                                    [OK]
richarvey/nginx-php-fpm           Container running Nginx + PHP-FPM capable of…   736                                     [OK]
linuxserver/nginx                 An Nginx container, brought to you by LinuxS…   73                                      
bitnami/nginx                     Bitnami nginx Docker Image                      70                                      [OK]
tiangolo/nginx-rtmp               Docker image with Nginx using the nginx-rtmp…   51                                      [OK]
nginxdemos/hello                  NGINX webserver that serves a simple page co…   24                                      [OK]
jc21/nginx-proxy-manager          Docker container for managing Nginx proxy ho…   23                                      
nginx/nginx-ingress               NGINX Ingress Controller for Kubernetes         20                                      
jlesage/nginx-proxy-manager       Docker container for Nginx Proxy Manager        20                                      [OK]
schmunk42/nginx-redirect          A very simple container to redirect HTTP tra…   17                                      [OK]
crunchgeek/nginx-pagespeed        Nginx with PageSpeed + GEO IP + VTS + more_s…   13                                      
blacklabelops/nginx               Dockerized Nginx Reverse Proxy Server.          12                                      [OK]
centos/nginx-18-centos7           Platform for running nginx 1.8 or building n…   11                                      
centos/nginx-112-centos7          Platform for running nginx 1.12 or building …   10                                      
nginxinc/nginx-unprivileged       Unprivileged NGINX Dockerfiles                  9                                       
nginx/nginx-prometheus-exporter   NGINX Prometheus Exporter                       5                                       
sophos/nginx-vts-exporter         Simple server that scrapes Nginx vts stats a…   5                                       [OK]
1science/nginx                    Nginx Docker images that include Consul Temp…   5                                       [OK]
mailu/nginx                       Mailu nginx frontend                            3                                       [OK]
pebbletech/nginx-proxy            nginx-proxy sets up a container running ngin…   2                                       [OK]
travix/nginx                      NGinx reverse proxy                             2                                       [OK]
centos/nginx-110-centos7          Platform for running nginx 1.10 or building …   0                                       
wodby/nginx                       Generic nginx                                   0                                       [OK]
ansibleplaybookbundle/nginx-apb   An APB to deploy NGINX                          0                                       [OK]
[root@node105 ~]#

2、拉取镜像-docker pull

[root@node105 ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
1ab2bdfe9778: Pull complete 
a17e64cfe253: Pull complete 
e1288088c7a8: Pull complete 
Digest: sha256:53ddb41e46de3d63376579acf46f9a41a8d7de33645db47a486de9769201fec9
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@node105 ~]#

 

3、列出本地镜像-docker images
下载完成后,在本地镜像列表里查到 REPOSITORY 为 nginx 的镜像

[root@node105 ~]# docker images nginx
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 5a3221f0137b 9 days ago 126MB
[root@node105 ~]#

4、根据镜像启动一个Nginx容器实例-docker run 

[root@node105 ~]# docker run --name nginx-test -d -p 8081:80 nginx
db8b3e2f1c647bc2589f04c3984374625455434449ee01e37f0b21163362b052

执行成功返回一行字符串,表示容器ID

--name 为容器设置一个名字

-d 后台运行
-p 端口进行映射,将本地8081端口映射到容器内部的80端口(:左侧是本地端口 右侧是容器内端口)
-P 容器内部端口随机映射到主机的高端口

5、查看容器运行情况-docker ps

[root@node105 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
db8b3e2f1c64 nginx "nginx -g ‘daemon of…" 2 minutes ago Up 2 minutes 0.0.0.0:8081->80/tcp nginx-test
[root@node105 ~]#

6、关闭容器-docker stop

[root@node105 ~]# docker stop nginx-test
nginx-test
[root@node105 ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@node105 ~]# 

7、启动容器-docker start

[root@node105 ~]# docker start nginx-test
nginx-test
[root@node105 ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
db8b3e2f1c64        nginx               "nginx -g ‘daemon of…"   16 minutes ago      Up 4 seconds        0.0.0.0:8081->80/tcp   nginx-test
[root@node105 ~]#

8、重启容器

[root@node105 ~]# docker restart nginx-test
nginx-test
[root@node105 ~]# docker kill -s HUP nginx-test
nginx-test
[root@node105 ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
db8b3e2f1c64        nginx               "nginx -g ‘daemon of…"   18 minutes ago      Up 25 seconds       0.0.0.0:8081->80/tcp   nginx-test
[root@node105 ~]# 

-s HUP 向容器发送HUP信号,表示重新加载

二、容器使用

 

参考:
CentOS Docker 安装
https://www.runoob.com/docker/centos-docker-install.html
Windows Docker 安装
https://www.runoob.com/docker/windows-docker-install.html
Docker 命令大全
https://www.runoob.com/docker/docker-command-manual.html
Docker 资源汇总
https://www.runoob.com/docker/docker-resources.html

 

【Docker学习之三】Docker查找拉取镜像、启动容器、容器使用

标签:proxy   完成后   book   you   sci   hellip   manage   gre   seconds   

原文地址:https://www.cnblogs.com/cac2020/p/11407036.html

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