如何用docker运行Nginx

1.获取镜像文件

#先搜索一下镜像文件是否存在
[root@localhost ~]# docker search nginx
NAME                                              DESCRIPTION                                      STARS     OFFICIAL   AUTOMATED
nginx                                             Official build of Nginx.                         18849     [OK]       
unit                                              Official build of NGINX Unit: Universal Web …   8         [OK]       
nginxinc/nginx-unprivileged                       Unprivileged NGINX Dockerfiles                   108                  
nginx/nginx-ingress                               NGINX and  NGINX Plus Ingress Controllers fo…   75                   
nginx/nginx-prometheus-exporter                   NGINX Prometheus Exporter for NGINX and NGIN…   33                   
nginx/unit                                        NGINX Unit is a dynamic web and application …   64                   
nginxinc/nginx-s3-gateway                         Authenticating and caching gateway based on …   1                    
nginx/nginx-ingress-operator                      NGINX Ingress Operator for NGINX and NGINX P…   0                    
nginxinc/amplify-agent                            NGINX Amplify Agent docker repository            1                    
nginx/nginx-quic-qns                              NGINX QUIC interop                               1                    
nginxinc/ingress-demo                             Ingress Demo                                     4                    
nginxproxy/nginx-proxy                            Automated Nginx reverse proxy for docker con…   98                   
nginxproxy/acme-companion                         Automated ACME SSL certificate generation fo…   120                  
bitnami/nginx                                     Bitnami nginx Docker Image                       171                  [OK]
bitnami/nginx-ingress-controller                  Bitnami Docker Image for NGINX Ingress Contr…   29                   [OK]
ubuntu/nginx                                      Nginx, a high-performance reverse proxy & we…   97                   
nginxinc/nginmesh_proxy_debug                                                                      0                    
nginxproxy/docker-gen                             Generate files from docker container meta-da…   12                   
nginxinc/mra-fakes3                                                                                0                    
kasmweb/nginx                                     An Nginx image based off nginx:alpine and in6                    
rancher/nginx-ingress-controller                                                                   11                   
nginxinc/ngx-rust-tool                                                                             0                    
nginxinc/mra_python_base                                                                           0                    
nginxinc/nginmesh_proxy_init                                                                       0                    
rancher/nginx-ingress-controller-defaultbackend                                                    2                    

#拉取,下载镜像
docker pull nginx

[root@localhost ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete 
a9edb18cadd1: Pull complete 
589b7251471a: Pull complete 
186b1aaa4aa6: Pull complete 
b4df32aa5a72: Pull complete 
a0bcbecc962e: Pull complete 
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

#查看本地的docker镜像有哪些
[root@localhost ~]# docker image ls
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
nginx        latest    605c77e624dd   19 months ago   141MB

#运行改Nginx镜像, 运行出具体的容器,然后这个容器中,就跑着一个Nginx服务
#运行镜像的命令,参数如下
docker run 参数  镜像的名字/id

# -d 后台运行容器
# -p 80:80  端口映射   宿主机端口:容器内端口  你访问宿主机的80端口,也就访问到了容器内的端口
#运行结果如下,docker run 命令会返回一个容器的id
[root@localhost ~]# docker run -d -p 80:80 nginx
10df2fecc26b8599ffd833d9763cf12009495ccb20d526b7bc0f00063c922ca7

#查看容器是否在运行
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                   CREATED              STATUS              PORTS                               NAMES
10df2fecc26b   nginx     "/docker-entrypoint.…"   About a minute ago   Up About a minute   0.0.0.0:80->80/tcp, :::80->80/tcp   boring_hopper

#此时访问宿主机的80端口,可以看到Nginx界面
ip:80

#停止容器命令
docker stop 容器id

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值