0
点赞
收藏
分享

微信扫一扫

5-Docker实例-安装nginx

1.拉取nginx镜像

命令:

docker search nginx

docker pull nginx

[root@centos79 ~]# docker search nginx
NAME                               DESCRIPTION                                      STARS     OFFICIAL   AUTOMATED
nginx                              Official build of Nginx.                         19325     [OK]       
unit                               Official build of NGINX Unit: Universal Web …   19        [OK]       
nginxinc/nginx-unprivileged        Unprivileged NGINX Dockerfiles                   136                  
nginx/nginx-ingress                NGINX and  NGINX Plus Ingress Controllers fo…   86                   
nginx/nginx-prometheus-exporter    NGINX Prometheus Exporter for NGINX and NGIN…   33                   
nginxinc/nginx-s3-gateway          Authenticating and caching gateway based on …   3                    
nginx/unit                         This repository is retired, use the Docker o…   64                   
nginx/nginx-ingress-operator       NGINX Ingress Operator for NGINX and NGINX P…   2                    
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…   119                  
nginxproxy/acme-companion          Automated ACME SSL certificate generation fo…   127                  
bitnami/nginx                      Bitnami nginx Docker Image                       180                  [OK]
bitnami/nginx-ingress-controller   Bitnami Docker Image for NGINX Ingress Contr…   32                   [OK]
ubuntu/nginx                       Nginx, a high-performance reverse proxy & we…   103                  
nginxinc/nginmesh_proxy_debug                                                       0                    
nginxproxy/docker-gen              Generate files from docker container meta-da…   14                   
kasmweb/nginx                      An Nginx image based off nginx:alpine and in…   6                    
nginxinc/mra-fakes3                                                                 0                    
rancher/nginx-ingress-controller                                                    11                   
nginxinc/ngx-rust-tool                                                              0                    
nginxinc/mra_python_base                                                            0                    
nginxinc/nginmesh_proxy_init                                                        0                    
[root@centos79 ~]# 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
[root@centos79 ~]# 
[root@centos79 ~]# docker images | grep nginx
nginx                                latest        605c77e624dd   23 months ago   141MB
[root@centos79 ~]#

2.创建volume进行目录挂载

命令:

docker volume create etc_nginx

docker volume create log_nginx

docker volume create share_nginx

[root@centos79 ~]# docker volume create etc_nginx
etc_nginx
[root@centos79 ~]# docker volume create log_nginx
log_nginx
[root@centos79 ~]# docker volume create share_nginx
share_nginx
[root@centos79 ~]# docker volume ls
DRIVER    VOLUME NAME
local     etc_nginx
local     log_nginx
local     share_nginx
[root@centos79 ~]#

3.使用nginx镜像运行容器

命令:

docker run -itd -p 80:80 --privileged --name mynginx -v etc_nginx:/etc/nginx -v log_nginx:/var/log/nginx -v share_nginx:/usr/share/nginx nginx:latest

[root@centos79 ~]# docker run -itd -p 80:80 --privileged --name mynginx -v etc_nginx:/etc/nginx -v log_nginx:/var/log/nginx -v share_nginx:/usr/share/nginx nginx:latest
3e4bdae429e3ccb9f803994ba61be97b50c6777b778482b86c4879a5510f3c0a
[root@centos79 ~]# docker ps -a | grep 3e4b
3e4bdae429e3   nginx:latest           "/docker-entrypoint.…"   23 seconds ago   Up 21 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp                                                      mynginx
[root@centos79 ~]# 
[root@centos79 volumes]# pwd
/var/lib/docker/volumes
[root@centos79 volumes]# ls
backingFsBlockDev  etc_nginx  log_nginx  metadata.db  share_nginx
[root@centos79 volumes]# cd etc_nginx/
[root@centos79 etc_nginx]# ls
_data
[root@centos79 etc_nginx]# cd _data/
[root@centos79 _data]# ls
conf.d  fastcgi_params  mime.types  modules  nginx.conf  scgi_params  uwsgi_params
[root@centos79 _data]# cd ../..
[root@centos79 volumes]# cd log_nginx/_data/
[root@centos79 _data]# ls
access.log  error.log
[root@centos79 _data]# cd ../..
[root@centos79 volumes]# cd share_nginx/_data/
[root@centos79 _data]# ls
html
[root@centos79 _data]# cd html/
[root@centos79 html]# ls
50x.html  index.html
[root@centos79 html]#

4.验证

http://172.20.10.12

5-Docker实例-安装nginx_nginx

举报

相关推荐

0 条评论